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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 73b43370b97701af8bc883f5d99ce0ccea3b69ff
4
- data.tar.gz: 89d1eb9d1131a6162d3dcf6926839051752a654c
3
+ metadata.gz: 142cd96919e530d70c6a0f5d1b53e3c32071c50c
4
+ data.tar.gz: 9a0d05eebfeaeb3655968ef2582901c8d787f910
5
5
  SHA512:
6
- metadata.gz: 44ca00d9fe5935c8c38050b8f6486e31e662593633214b935949d322b5d2ca21e9095c2a571defb2574b516d98f80b700f14ac0c4827355993444b9acb501f31
7
- data.tar.gz: 325cd7b686ec4f7e65821c087a7a8229a02e82a22518b6ac21d5db2813213030eced4b8d13f09ded4635aeea2b63107656f069183ce6860baeb263a7ca31fe30
6
+ metadata.gz: 688984f42e9b3c71c120455f54491b55b8f1ef6e038fdd761a7d04fb50895a49a17e6ae6ec9d9cfc4d00eb364c6d6d9b92a20a2a2697725aa0c94ce0d57422af
7
+ data.tar.gz: 2b145b620e889c5a247a8918e3f7bb0087718a8e3b11ad6f9d545114d54ec1a067b48b27b36b19b90b96f99859a457edeff156457a225941a7221ecc64594eb4
@@ -0,0 +1,10 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ - 1.9.3
5
+ - jruby-18mode # JRuby in 1.8 mode
6
+ - jruby-19mode # JRuby in 1.9 mode
7
+ - rbx-18mode
8
+ - rbx-19mode
9
+ - 1.8.7
10
+ - ree
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
@@ -55,7 +55,7 @@ class Bound
55
55
  end
56
56
 
57
57
  def call_on(object)
58
- object.public_send @name
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 "DEPRECATED: use get_attributes"
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
- @receiver.public_send "#{key}=", value
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 => e
274
+ rescue NoMethodError
274
275
  value = nil
275
276
  raise ArgumentError, "missing #{attribute.name}" if attribute.required?
276
277
  end
277
278
 
278
- @receiver.public_send "#{attribute.name}=", value
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
@@ -1,3 +1,3 @@
1
1
  class Bound
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -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]{14,}/, inspection)
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={.*}/, inspection)
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(/DEPRECATED/, deprecation_warning)
236
+ assert_match(/deprecated/, deprecation_warning)
237
237
  end
238
238
  end
239
239
 
@@ -3,18 +3,18 @@ require 'spec_helper'
3
3
  # Test support object
4
4
  describe HashObject do
5
5
 
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
-
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
@@ -6,37 +6,6 @@ end
6
6
  require 'minitest/autorun'
7
7
  require 'minitest/spec'
8
8
 
9
- require 'bound'
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
- def self.map_value(value)
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.0
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-09-29 00:00:00.000000000 Z
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.6
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