bound 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +10 -0
- data/README.md +2 -0
- data/lib/bound.rb +11 -5
- data/lib/bound/version.rb +1 -1
- data/spec/bound_spec.rb +3 -3
- data/spec/hash_object_spec.rb +12 -12
- data/spec/spec_helper.rb +2 -33
- data/spec/support/hash_object.rb +32 -0
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 142cd96919e530d70c6a0f5d1b53e3c32071c50c
|
4
|
+
data.tar.gz: 9a0d05eebfeaeb3655968ef2582901c8d787f910
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 688984f42e9b3c71c120455f54491b55b8f1ef6e038fdd761a7d04fb50895a49a17e6ae6ec9d9cfc4d00eb364c6d6d9b92a20a2a2697725aa0c94ce0d57422af
|
7
|
+
data.tar.gz: 2b145b620e889c5a247a8918e3f7bb0087718a8e3b11ad6f9d545114d54ec1a067b48b27b36b19b90b96f99859a457edeff156457a225941a7221ecc64594eb4
|
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# Bound
|
2
2
|
|
3
|
+
[![Build Status](https://travis-ci.org/neopoly/bound.png)](https://travis-ci.org/neopoly/bound) [![Gem Version](https://badge.fury.io/rb/bound.png)](http://badge.fury.io/rb/bound) [![Code Climate](https://codeclimate.com/github/neopoly/bound.png)](https://codeclimate.com/github/neopoly/bound)
|
4
|
+
|
3
5
|
TODO: Write a gem description
|
4
6
|
|
5
7
|
## Installation
|
data/lib/bound.rb
CHANGED
@@ -55,7 +55,7 @@ class Bound
|
|
55
55
|
end
|
56
56
|
|
57
57
|
def call_on(object)
|
58
|
-
object.
|
58
|
+
object.send @name
|
59
59
|
end
|
60
60
|
|
61
61
|
def valid?
|
@@ -210,7 +210,7 @@ class Bound
|
|
210
210
|
end
|
211
211
|
|
212
212
|
def __attributes__
|
213
|
-
puts "
|
213
|
+
puts "BoundClass#__attributes__ is deprecated: use get_attributes"
|
214
214
|
get_attributes.map(&:name)
|
215
215
|
end
|
216
216
|
|
@@ -256,7 +256,8 @@ class Bound
|
|
256
256
|
|
257
257
|
def seed(hash)
|
258
258
|
hash.each do |key, value|
|
259
|
-
|
259
|
+
method = "#{key}="
|
260
|
+
@receiver.send method, value
|
260
261
|
end
|
261
262
|
end
|
262
263
|
end
|
@@ -270,12 +271,17 @@ class Bound
|
|
270
271
|
@receiver.get_attributes.each do |attribute|
|
271
272
|
begin
|
272
273
|
value = attribute.call_on(object)
|
273
|
-
rescue NoMethodError
|
274
|
+
rescue NoMethodError
|
274
275
|
value = nil
|
275
276
|
raise ArgumentError, "missing #{attribute.name}" if attribute.required?
|
276
277
|
end
|
277
278
|
|
278
|
-
|
279
|
+
method = "#{attribute.name}="
|
280
|
+
if @receiver.respond_to?(method)
|
281
|
+
@receiver.send method, value
|
282
|
+
else
|
283
|
+
raise NoMethodError, "undefined method `#{method}' for #{self}"
|
284
|
+
end
|
279
285
|
end
|
280
286
|
end
|
281
287
|
end
|
data/lib/bound/version.rb
CHANGED
data/spec/bound_spec.rb
CHANGED
@@ -85,11 +85,11 @@ describe Bound do
|
|
85
85
|
assert_match(/name="foo"/, inspection)
|
86
86
|
assert_match(/age=23/, inspection)
|
87
87
|
assert_match(/User/, inspection)
|
88
|
-
assert_match(/0x[0-9a-f]
|
88
|
+
assert_match(/0x[0-9a-f]+/, inspection)
|
89
89
|
end
|
90
90
|
|
91
91
|
it 'does not display @hash' do
|
92
|
-
refute_match(/@hash
|
92
|
+
refute_match(/@hash=/, inspection)
|
93
93
|
end
|
94
94
|
end
|
95
95
|
|
@@ -233,7 +233,7 @@ describe Bound do
|
|
233
233
|
user.__attributes__
|
234
234
|
end
|
235
235
|
|
236
|
-
assert_match(/
|
236
|
+
assert_match(/deprecated/, deprecation_warning)
|
237
237
|
end
|
238
238
|
end
|
239
239
|
|
data/spec/hash_object_spec.rb
CHANGED
@@ -3,18 +3,18 @@ require 'spec_helper'
|
|
3
3
|
# Test support object
|
4
4
|
describe HashObject do
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
6
|
+
subject { HashObject.new(hash) }
|
7
|
+
let(:hash) do
|
8
|
+
{
|
9
|
+
:name => 'Steve',
|
10
|
+
:address => {:street => 'Mainstreet'},
|
11
|
+
:posts => [
|
12
|
+
{:title => 'It is christmas'},
|
13
|
+
{:title => 'NOT'}
|
14
|
+
]
|
15
|
+
}
|
16
|
+
end
|
17
|
+
|
18
18
|
it 'maps an intergalactic hash' do
|
19
19
|
assert_equal hash[:name], subject.name
|
20
20
|
assert_equal hash[:address][:street], subject.address.street
|
data/spec/spec_helper.rb
CHANGED
@@ -6,37 +6,6 @@ end
|
|
6
6
|
require 'minitest/autorun'
|
7
7
|
require 'minitest/spec'
|
8
8
|
|
9
|
-
require '
|
10
|
-
|
11
|
-
# HashObject behaves like an OpenStruct
|
12
|
-
# but there is no method_missing involved.
|
13
|
-
#
|
14
|
-
# Missing keys in the source hash result in
|
15
|
-
# NoMethodErrors on a later call
|
16
|
-
#
|
17
|
-
# OpenStruct.new(:id => 2).name # => nil
|
18
|
-
# HashObject.new(:id => 2).name # => NoMethodError
|
19
|
-
#
|
20
|
-
class HashObject
|
21
|
-
def self.new(hash)
|
22
|
-
attributes = hash.keys
|
23
|
-
values = hash.values
|
24
|
-
if attributes.empty?
|
25
|
-
Class.new
|
26
|
-
else
|
27
|
-
mapped_values = values.map { |v| map_value(v) }
|
28
|
-
Struct.new(*attributes).new(*mapped_values)
|
29
|
-
end
|
30
|
-
end
|
9
|
+
require 'support/hash_object'
|
31
10
|
|
32
|
-
|
33
|
-
case value
|
34
|
-
when Hash
|
35
|
-
HashObject.new(value)
|
36
|
-
when Array
|
37
|
-
value.map { |v| map_value(v) }
|
38
|
-
else
|
39
|
-
value
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
11
|
+
require 'bound'
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# HashObject behaves like an OpenStruct
|
2
|
+
# but there is no method_missing involved.
|
3
|
+
#
|
4
|
+
# Missing keys in the source hash result in
|
5
|
+
# NoMethodErrors on a later call
|
6
|
+
#
|
7
|
+
# OpenStruct.new(:id => 2).name # => nil
|
8
|
+
# HashObject.new(:id => 2).name # => NoMethodError
|
9
|
+
#
|
10
|
+
class HashObject
|
11
|
+
def self.new(hash)
|
12
|
+
attributes = hash.keys
|
13
|
+
values = hash.values
|
14
|
+
if attributes.empty?
|
15
|
+
Class.new
|
16
|
+
else
|
17
|
+
mapped_values = values.map { |v| map_value(v) }
|
18
|
+
Struct.new(*attributes).new(*mapped_values)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.map_value(value)
|
23
|
+
case value
|
24
|
+
when Hash
|
25
|
+
HashObject.new(value)
|
26
|
+
when Array
|
27
|
+
value.map { |v| map_value(v) }
|
28
|
+
else
|
29
|
+
value
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
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.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jakob Holderbaum
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-10-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -76,6 +76,7 @@ extensions: []
|
|
76
76
|
extra_rdoc_files: []
|
77
77
|
files:
|
78
78
|
- .gitignore
|
79
|
+
- .travis.yml
|
79
80
|
- Gemfile
|
80
81
|
- LICENSE.txt
|
81
82
|
- README.md
|
@@ -86,6 +87,7 @@ files:
|
|
86
87
|
- spec/bound_spec.rb
|
87
88
|
- spec/hash_object_spec.rb
|
88
89
|
- spec/spec_helper.rb
|
90
|
+
- spec/support/hash_object.rb
|
89
91
|
homepage: ''
|
90
92
|
licenses:
|
91
93
|
- MIT
|
@@ -106,7 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
106
108
|
version: '0'
|
107
109
|
requirements: []
|
108
110
|
rubyforge_project:
|
109
|
-
rubygems_version: 2.0.
|
111
|
+
rubygems_version: 2.0.0
|
110
112
|
signing_key:
|
111
113
|
specification_version: 4
|
112
114
|
summary: Implements a nice helper for fast boundary definitions
|
@@ -114,3 +116,4 @@ test_files:
|
|
114
116
|
- spec/bound_spec.rb
|
115
117
|
- spec/hash_object_spec.rb
|
116
118
|
- spec/spec_helper.rb
|
119
|
+
- spec/support/hash_object.rb
|