deepstruct 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +2 -6
- data/lib/deepstruct.rb +10 -5
- data/lib/deepstruct/version.rb +1 -1
- data/spec/deepstruct_spec.rb +8 -0
- metadata +10 -5
data/README.markdown
CHANGED
@@ -11,15 +11,11 @@ An adapter that wraps common ruby data-structures and makes them look like prope
|
|
11
11
|
Installation
|
12
12
|
============
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
git clone git@github.com:simen/deepstruct.git
|
17
|
-
cd deepstruct
|
18
|
-
rake install
|
14
|
+
gem install deepstruct
|
19
15
|
|
20
16
|
Or if you use the awesomeness that is bundler, you stick this in your Gemfile:
|
21
17
|
|
22
|
-
gem "deepstruct"
|
18
|
+
gem "deepstruct"
|
23
19
|
|
24
20
|
Usage
|
25
21
|
=====
|
data/lib/deepstruct.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'set'
|
2
|
+
|
1
3
|
module DeepStruct
|
2
4
|
class DeepWrapper
|
3
5
|
def initialize(value)
|
@@ -55,7 +57,10 @@ module DeepStruct
|
|
55
57
|
def method_missing(method, *args, &block)
|
56
58
|
return @value.send(method, *args, &block) if @value.respond_to?(method)
|
57
59
|
method = method.to_s
|
58
|
-
if method.chomp!('
|
60
|
+
if method.chomp!('?')
|
61
|
+
key = method.to_sym
|
62
|
+
@value.has_key?(key) && !!@value[key]
|
63
|
+
elsif method.chomp!('=')
|
59
64
|
raise ArgumentError, "wrong number of arguments (#{arg_count} for 1)", caller(1) if args.length != 1
|
60
65
|
self[method] = args[0]
|
61
66
|
elsif args.length == 0 && self.has_key?(method)
|
@@ -84,11 +89,11 @@ module DeepStruct
|
|
84
89
|
def self.wrap(value)
|
85
90
|
case value
|
86
91
|
when Hash
|
87
|
-
|
88
|
-
when
|
89
|
-
|
92
|
+
HashWrapper.new(value)
|
93
|
+
when Array, Set
|
94
|
+
ArrayWrapper.new(value)
|
90
95
|
else
|
91
|
-
|
96
|
+
value
|
92
97
|
end
|
93
98
|
end
|
94
99
|
end
|
data/lib/deepstruct/version.rb
CHANGED
data/spec/deepstruct_spec.rb
CHANGED
@@ -114,6 +114,14 @@ describe DeepStruct do
|
|
114
114
|
struct = DeepStruct.wrap({:a => true})
|
115
115
|
struct.respond_to?(:a=).should be_true
|
116
116
|
end
|
117
|
+
end
|
117
118
|
|
119
|
+
describe "predicate methods" do
|
120
|
+
subject { DeepStruct.wrap({:a => 1, :b => false, :c => nil, :d => true}) }
|
121
|
+
its(:a?) { should be_true }
|
122
|
+
its(:b?) { should be_false }
|
123
|
+
its(:c?) { should be_false }
|
124
|
+
its(:d?) { should be_true }
|
118
125
|
end
|
126
|
+
|
119
127
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: deepstruct
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2012-06-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement:
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,7 +21,12 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements:
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
25
30
|
description: A sibling of ostruct that handles deeply nested structures and basic
|
26
31
|
data type detection
|
27
32
|
email:
|
@@ -60,7 +65,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
60
65
|
version: '0'
|
61
66
|
requirements: []
|
62
67
|
rubyforge_project: deepstruct
|
63
|
-
rubygems_version: 1.8.
|
68
|
+
rubygems_version: 1.8.24
|
64
69
|
signing_key:
|
65
70
|
specification_version: 3
|
66
71
|
summary: A sibling of ostruct that handles deeply nested structures and basic data
|