ficus 0.0.4 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/ficus.gemspec +2 -2
- metadata +15 -2
- data/lib/recursive-open-struct.rb +0 -93
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8e2f42373c4373ad219fa88df98d44ff83916f35
|
4
|
+
data.tar.gz: aec31ba49eb8074354256fec29d444d4aaa8612a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d6d56312dd96ae16ddad988fe555152c4c1361af4ab299495521f54da4dbb44d0af6fd77b53dcaa491fdd4c52108aa27da18f84df707402438968dd23ca37045
|
7
|
+
data.tar.gz: 1d237e3b1bb559029b6f415af05f4575c103faf664f42fc9e45a3a6c7cb28a65185ed8725b1a235433397b71bfe7e097e75c35cc22bdadeabdb820738379ad87
|
data/ficus.gemspec
CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = "ficus"
|
7
|
-
spec.version = '0.0.
|
7
|
+
spec.version = '0.0.5'
|
8
8
|
spec.authors = ["Drew Fradette"]
|
9
9
|
spec.email = ["drew.fradette@gmail.com"]
|
10
10
|
spec.description = 'A runtime validation configuration DSL'
|
@@ -22,5 +22,5 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.add_development_dependency 'rspec'
|
23
23
|
spec.add_development_dependency 'simplecov' if RUBY_VERSION >= '1.9'
|
24
24
|
|
25
|
-
|
25
|
+
spec.add_dependency 'recursive-open-struct', '>= 0.4.5'
|
26
26
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ficus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Drew Fradette
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - '>='
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: recursive-open-struct
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.4.5
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.4.5
|
69
83
|
description: A runtime validation configuration DSL
|
70
84
|
email:
|
71
85
|
- drew.fradette@gmail.com
|
@@ -83,7 +97,6 @@ files:
|
|
83
97
|
- lib/ficus/dsl.rb
|
84
98
|
- lib/ficus/exceptions.rb
|
85
99
|
- lib/ficus/loader.rb
|
86
|
-
- lib/recursive-open-struct.rb
|
87
100
|
- spec/ficus_spec.rb
|
88
101
|
- spec/spec_helper.rb
|
89
102
|
homepage: https://github.com/drewfradette/ruby-ficus
|
@@ -1,93 +0,0 @@
|
|
1
|
-
require 'ostruct'
|
2
|
-
|
3
|
-
class RecursiveOpenStruct < OpenStruct
|
4
|
-
VERSION = "0.4.3"
|
5
|
-
|
6
|
-
def initialize(h=nil, args={})
|
7
|
-
@recurse_over_arrays = args.fetch(:recurse_over_arrays,false)
|
8
|
-
super(h)
|
9
|
-
@sub_elements = {}
|
10
|
-
end
|
11
|
-
|
12
|
-
def to_h
|
13
|
-
@table.dup.update(@sub_elements) do |k, oldval, newval|
|
14
|
-
if newval.kind_of?(self.class)
|
15
|
-
newval.to_h
|
16
|
-
elsif newval.kind_of?(Array)
|
17
|
-
newval.map { |a| a.kind_of?(self.class) ? a.to_h : a }
|
18
|
-
else
|
19
|
-
raise "Cached value of unsupported type: #{newval.inspect}"
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
def new_ostruct_member(name)
|
25
|
-
name = name.to_sym
|
26
|
-
unless self.respond_to?(name)
|
27
|
-
class << self; self; end.class_eval do
|
28
|
-
define_method(name) do
|
29
|
-
v = @table[name]
|
30
|
-
if v.is_a?(Hash)
|
31
|
-
@sub_elements[name] ||= self.class.new(v, :recurse_over_arrays => @recurse_over_arrays)
|
32
|
-
elsif v.is_a?(Array) and @recurse_over_arrays
|
33
|
-
@sub_elements[name] ||= recurse_over_array v
|
34
|
-
else
|
35
|
-
v
|
36
|
-
end
|
37
|
-
end
|
38
|
-
define_method("#{name}=") { |x| modifiable[name] = x }
|
39
|
-
define_method("#{name}_as_a_hash") { @table[name] }
|
40
|
-
end
|
41
|
-
end
|
42
|
-
name
|
43
|
-
end
|
44
|
-
|
45
|
-
def recurse_over_array array
|
46
|
-
array.map do |a|
|
47
|
-
if a.is_a? Hash
|
48
|
-
self.class.new(a, :recurse_over_arrays => true)
|
49
|
-
elsif a.is_a? Array
|
50
|
-
recurse_over_array a
|
51
|
-
else
|
52
|
-
a
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
def debug_inspect(io = STDOUT, indent_level = 0, recursion_limit = 12)
|
58
|
-
display_recursive_open_struct(io, @table, indent_level, recursion_limit)
|
59
|
-
end
|
60
|
-
|
61
|
-
def display_recursive_open_struct(io, ostrct_or_hash, indent_level, recursion_limit)
|
62
|
-
|
63
|
-
if recursion_limit <= 0 then
|
64
|
-
# protection against recursive structure (like in the tests)
|
65
|
-
io.puts ' '*indent_level + '(recursion limit reached)'
|
66
|
-
else
|
67
|
-
#puts ostrct_or_hash.inspect
|
68
|
-
if ostrct_or_hash.is_a?(self.class) then
|
69
|
-
ostrct_or_hash = ostrct_or_hash.marshal_dump
|
70
|
-
end
|
71
|
-
|
72
|
-
# We'll display the key values like this : key = value
|
73
|
-
# to align display, we look for the maximum key length of the data that will be displayed
|
74
|
-
# (everything except hashes)
|
75
|
-
data_indent = ostrct_or_hash \
|
76
|
-
.reject { |k, v| v.is_a?(self.class) || v.is_a?(Hash) } \
|
77
|
-
.max {|a,b| a[0].to_s.length <=> b[0].to_s.length}[0].to_s.length
|
78
|
-
# puts "max length = #{data_indent}"
|
79
|
-
|
80
|
-
ostrct_or_hash.each do |key, value|
|
81
|
-
if (value.is_a?(self.class) || value.is_a?(Hash)) then
|
82
|
-
io.puts ' '*indent_level + key.to_s + '.'
|
83
|
-
display_recursive_open_struct(io, value, indent_level + 1, recursion_limit - 1)
|
84
|
-
else
|
85
|
-
io.puts ' '*indent_level + key.to_s + ' '*(data_indent - key.to_s.length) + ' = ' + value.inspect
|
86
|
-
end
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
true
|
91
|
-
end
|
92
|
-
|
93
|
-
end
|