bound 0.0.2 → 0.0.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4f851ca90e635f3f6ac942e875e89fb87670ec9d
4
- data.tar.gz: de5b33718676163ed2d8177b1a7b887b59b33b92
3
+ metadata.gz: abad97e3b3b8e96cf9b42a0775bb12fdd347b325
4
+ data.tar.gz: d8e735b724ae91ba5745d3ee090840f073541c2d
5
5
  SHA512:
6
- metadata.gz: 1f3153699f140a1e55ba3ab153b76a7ad435acc00cc0d2640b958eaf0364f36d24118bd678944e83ccc9cf36aef0172c097602c1ccd0a772ed4708d843f1e691
7
- data.tar.gz: 8a4f3c15288c91e8387acf7b87e4ff7ec430d5d70993eccbba3ab605291f74dc69c0ed80dffbe376d3c14f748ba7fd206975447a3ef443c7a495a03b145ad2c1
6
+ metadata.gz: c8d7902861b1dad1ee41a1fa2d7fcc372a0e045bb8da9c55eee63283b415ab049effb939917a16a34e7233addf729216d2cdbf75534c3a41e6deb5e36a5db6a1
7
+ data.tar.gz: 69eeba09a438642aa2b618055158326d632383c9b825f6bf6d1a744e78af8ea1d95ad7470e75147f6be2acc60ff29ef472534934575a408a2c64340bab313cad
data/bound.gemspec CHANGED
@@ -8,7 +8,7 @@ Gem::Specification.new do |spec|
8
8
  spec.version = Bound::VERSION
9
9
  spec.authors = ["Jakob Holderbaum", "Jan Owiesniak"]
10
10
  spec.email = ["jh@neopoly.de", "jo@neopoly.de"]
11
- spec.summary = %q{Implements a nice helper for fas boundary definitions}
11
+ spec.summary = %q{Implements a nice helper for fast boundary definitions}
12
12
  spec.homepage = ""
13
13
  spec.license = "MIT"
14
14
 
data/lib/bound.rb CHANGED
@@ -36,6 +36,8 @@ class Bound
36
36
  []
37
37
  end
38
38
  end
39
+
40
+ alias :build :new
39
41
  end
40
42
 
41
43
  def initialize(hash_or_object)
@@ -67,29 +69,17 @@ class Bound
67
69
  @hash = hash_or_object
68
70
  else
69
71
  @hash = {}
70
- insert_attributes_into_hash(hash_or_object)
71
- insert_optionals_into_hash(hash_or_object)
72
- end
73
- end
74
-
75
- def insert_attributes_into_hash(object)
76
- self.class.attributes.inject(@hash) do |h, attr|
77
- begin
78
- h[attr] = object.public_send(attr)
79
- rescue NoMethodError
80
- raise ArgumentError.new("Missing attribute: #{attr}")
81
- end
82
- h
72
+ insert_into_hash(self.class.attributes, hash_or_object)
73
+ insert_into_hash(self.class.optionals, hash_or_object)
83
74
  end
84
75
  end
85
76
 
86
- def insert_optionals_into_hash(object)
87
- self.class.optionals.inject(@hash) do |h, attr|
77
+ def insert_into_hash(attributes, object)
78
+ attributes.each_with_object(@hash) do |attr, h|
88
79
  begin
89
80
  h[attr] = object.public_send(attr)
90
81
  rescue NoMethodError
91
82
  end
92
- h
93
83
  end
94
84
  end
95
85
  end
data/lib/bound/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  class Bound
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/spec/bound_spec.rb CHANGED
@@ -7,6 +7,15 @@ describe Bound do
7
7
  let(:hash) { {:name => 'foo', :age => 23} }
8
8
 
9
9
  it 'sets all attributes' do
10
+ [hash, object].each do |subject|
11
+ user = User.build(subject)
12
+
13
+ assert_equal hash[:name], user.name
14
+ assert_equal hash[:age], user.age
15
+ end
16
+ end
17
+
18
+ it 'also sets all attributes with new instead of build' do
10
19
  [hash, object].each do |subject|
11
20
  user = User.new(subject)
12
21
 
@@ -20,7 +29,7 @@ describe Bound do
20
29
 
21
30
  [hash, object].each do |subject|
22
31
  exception = assert_raises ArgumentError, subject.inspect do
23
- User.new(subject)
32
+ User.build(subject)
24
33
  end
25
34
 
26
35
  assert_match(/missing.+age/i, exception.message)
@@ -31,7 +40,7 @@ describe Bound do
31
40
  hash[:age] = nil
32
41
 
33
42
  [hash, object].each do |subject|
34
- User.new(subject)
43
+ User.build(subject)
35
44
  end
36
45
  end
37
46
 
@@ -40,7 +49,7 @@ describe Bound do
40
49
  subject = hash
41
50
 
42
51
  exception = assert_raises ArgumentError, subject.inspect do
43
- User.new(subject)
52
+ User.build(subject)
44
53
  end
45
54
 
46
55
  assert_match(/unknown.+gender/i, exception.message)
@@ -51,7 +60,7 @@ describe Bound do
51
60
 
52
61
  it 'sets optional attributes' do
53
62
  [hash, object].each do |subject|
54
- user = UserWithoutAge.new(subject)
63
+ user = UserWithoutAge.build(subject)
55
64
 
56
65
  assert_equal hash[:age], user.age
57
66
  end
@@ -61,7 +70,7 @@ describe Bound do
61
70
  hash.delete :age
62
71
 
63
72
  [hash, object].each do |subject|
64
- UserWithoutAge.new(subject)
73
+ UserWithoutAge.build(subject)
65
74
  end
66
75
  end
67
76
 
@@ -69,7 +78,7 @@ describe Bound do
69
78
  hash[:age] = nil
70
79
 
71
80
  [hash, object].each do |subject|
72
- UserWithoutAge.new(subject)
81
+ UserWithoutAge.build(subject)
73
82
  end
74
83
  end
75
84
  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.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jakob Holderbaum
@@ -94,7 +94,7 @@ rubyforge_project:
94
94
  rubygems_version: 2.0.0
95
95
  signing_key:
96
96
  specification_version: 4
97
- summary: Implements a nice helper for fas boundary definitions
97
+ summary: Implements a nice helper for fast boundary definitions
98
98
  test_files:
99
99
  - spec/bound_spec.rb
100
100
  - spec/spec_helper.rb