bound 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/bound/version.rb +1 -1
- data/spec/hash_object_spec.rb +3 -1
- data/spec/support/hash_object.rb +35 -6
- metadata +27 -11
- checksums.yaml +0 -7
data/lib/bound/version.rb
CHANGED
data/spec/hash_object_spec.rb
CHANGED
@@ -11,7 +11,8 @@ describe HashObject do
|
|
11
11
|
:posts => [
|
12
12
|
{:title => 'It is christmas'},
|
13
13
|
{:title => 'NOT'}
|
14
|
-
]
|
14
|
+
],
|
15
|
+
:living? => true
|
15
16
|
}
|
16
17
|
end
|
17
18
|
|
@@ -21,5 +22,6 @@ describe HashObject do
|
|
21
22
|
assert_equal hash[:posts].size, subject.posts.size
|
22
23
|
assert_equal hash[:posts][0][:title], subject.posts[0].title
|
23
24
|
assert_equal hash[:posts][1][:title], subject.posts[1].title
|
25
|
+
assert_equal hash[:living?], subject.living?
|
24
26
|
end
|
25
27
|
end
|
data/spec/support/hash_object.rb
CHANGED
@@ -7,16 +7,29 @@
|
|
7
7
|
# OpenStruct.new(:id => 2).name # => nil
|
8
8
|
# HashObject.new(:id => 2).name # => NoMethodError
|
9
9
|
#
|
10
|
+
# We also can not us struct, because it breaks on 1.9.3
|
11
|
+
# with ?-postifxed attributes.
|
12
|
+
#
|
13
|
+
# Hence this bare-metal implementation
|
14
|
+
#
|
10
15
|
class HashObject
|
11
16
|
def self.new(hash)
|
12
17
|
attributes = hash.keys
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
18
|
+
|
19
|
+
cls = Class.new
|
20
|
+
|
21
|
+
attributes.each do |attr|
|
22
|
+
define_accessor cls, attr
|
23
|
+
end
|
24
|
+
|
25
|
+
instance = cls.new
|
26
|
+
|
27
|
+
attributes.each do |attr|
|
28
|
+
value = map_value(hash[attr])
|
29
|
+
assign_value instance, attr, value
|
19
30
|
end
|
31
|
+
|
32
|
+
instance
|
20
33
|
end
|
21
34
|
|
22
35
|
def self.map_value(value)
|
@@ -29,4 +42,20 @@ class HashObject
|
|
29
42
|
value
|
30
43
|
end
|
31
44
|
end
|
45
|
+
|
46
|
+
def self.define_accessor(cls, attribute)
|
47
|
+
cls.send :define_method, :"#{attribute}=" do |a|
|
48
|
+
@suffix_attributes ||= {}
|
49
|
+
@suffix_attributes[attribute] = a
|
50
|
+
end
|
51
|
+
|
52
|
+
cls.send :define_method, :"#{attribute}" do
|
53
|
+
@suffix_attributes ||= {}
|
54
|
+
@suffix_attributes[attribute]
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def self.assign_value(instance, attr, value)
|
59
|
+
instance.send :"#{attr}=", value
|
60
|
+
end
|
32
61
|
end
|
metadata
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bound
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
|
+
prerelease:
|
5
6
|
platform: ruby
|
6
7
|
authors:
|
7
8
|
- Jakob Holderbaum
|
@@ -9,11 +10,12 @@ authors:
|
|
9
10
|
autorequire:
|
10
11
|
bindir: bin
|
11
12
|
cert_chain: []
|
12
|
-
date: 2013-10-
|
13
|
+
date: 2013-10-02 00:00:00.000000000 Z
|
13
14
|
dependencies:
|
14
15
|
- !ruby/object:Gem::Dependency
|
15
16
|
name: bundler
|
16
17
|
requirement: !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
17
19
|
requirements:
|
18
20
|
- - ~>
|
19
21
|
- !ruby/object:Gem::Version
|
@@ -21,6 +23,7 @@ dependencies:
|
|
21
23
|
type: :development
|
22
24
|
prerelease: false
|
23
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
24
27
|
requirements:
|
25
28
|
- - ~>
|
26
29
|
- !ruby/object:Gem::Version
|
@@ -28,20 +31,23 @@ dependencies:
|
|
28
31
|
- !ruby/object:Gem::Dependency
|
29
32
|
name: rake
|
30
33
|
requirement: !ruby/object:Gem::Requirement
|
34
|
+
none: false
|
31
35
|
requirements:
|
32
|
-
- - '>='
|
36
|
+
- - ! '>='
|
33
37
|
- !ruby/object:Gem::Version
|
34
38
|
version: '0'
|
35
39
|
type: :development
|
36
40
|
prerelease: false
|
37
41
|
version_requirements: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
38
43
|
requirements:
|
39
|
-
- - '>='
|
44
|
+
- - ! '>='
|
40
45
|
- !ruby/object:Gem::Version
|
41
46
|
version: '0'
|
42
47
|
- !ruby/object:Gem::Dependency
|
43
48
|
name: minitest
|
44
49
|
requirement: !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
45
51
|
requirements:
|
46
52
|
- - ~>
|
47
53
|
- !ruby/object:Gem::Version
|
@@ -49,6 +55,7 @@ dependencies:
|
|
49
55
|
type: :development
|
50
56
|
prerelease: false
|
51
57
|
version_requirements: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
52
59
|
requirements:
|
53
60
|
- - ~>
|
54
61
|
- !ruby/object:Gem::Version
|
@@ -56,15 +63,17 @@ dependencies:
|
|
56
63
|
- !ruby/object:Gem::Dependency
|
57
64
|
name: simplecov
|
58
65
|
requirement: !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
59
67
|
requirements:
|
60
|
-
- - '>='
|
68
|
+
- - ! '>='
|
61
69
|
- !ruby/object:Gem::Version
|
62
70
|
version: '0'
|
63
71
|
type: :development
|
64
72
|
prerelease: false
|
65
73
|
version_requirements: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
66
75
|
requirements:
|
67
|
-
- - '>='
|
76
|
+
- - ! '>='
|
68
77
|
- !ruby/object:Gem::Version
|
69
78
|
version: '0'
|
70
79
|
description:
|
@@ -91,26 +100,33 @@ files:
|
|
91
100
|
homepage: ''
|
92
101
|
licenses:
|
93
102
|
- MIT
|
94
|
-
metadata: {}
|
95
103
|
post_install_message:
|
96
104
|
rdoc_options: []
|
97
105
|
require_paths:
|
98
106
|
- lib
|
99
107
|
required_ruby_version: !ruby/object:Gem::Requirement
|
108
|
+
none: false
|
100
109
|
requirements:
|
101
|
-
- - '>='
|
110
|
+
- - ! '>='
|
102
111
|
- !ruby/object:Gem::Version
|
103
112
|
version: '0'
|
113
|
+
segments:
|
114
|
+
- 0
|
115
|
+
hash: -3582315724912543482
|
104
116
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
117
|
+
none: false
|
105
118
|
requirements:
|
106
|
-
- - '>='
|
119
|
+
- - ! '>='
|
107
120
|
- !ruby/object:Gem::Version
|
108
121
|
version: '0'
|
122
|
+
segments:
|
123
|
+
- 0
|
124
|
+
hash: -3582315724912543482
|
109
125
|
requirements: []
|
110
126
|
rubyforge_project:
|
111
|
-
rubygems_version:
|
127
|
+
rubygems_version: 1.8.25
|
112
128
|
signing_key:
|
113
|
-
specification_version:
|
129
|
+
specification_version: 3
|
114
130
|
summary: Implements a nice helper for fast boundary definitions
|
115
131
|
test_files:
|
116
132
|
- spec/bound_spec.rb
|
checksums.yaml
DELETED
@@ -1,7 +0,0 @@
|
|
1
|
-
---
|
2
|
-
SHA1:
|
3
|
-
metadata.gz: 0c59c6c0f35aaaddeab4dfbea0f9987845b3f1be
|
4
|
-
data.tar.gz: 9046059a697cd8300cb0d3b699729f03f9ba0c82
|
5
|
-
SHA512:
|
6
|
-
metadata.gz: bc0c1d56bb48519bd7fa99a5e1594fa10f1140f694ec16b46b49ded5249a99d74a708302210dc5fc07ec1859d621bb8f2167d105ddc54d80caccb9ac1c902181
|
7
|
-
data.tar.gz: 397d6a4af2cef4b156b638c13d3f02455ddd9254e8e193a7f1cb6aec34b0bf2400c9a691537e80afd38ded7657d0799a6a70982e6bd8c2731dc9881145ce143d
|