bound 0.0.1 → 0.0.2

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: 734a7fe5bfbce0c1bfc3b0aa576dddaf6f7a74ed
4
- data.tar.gz: 45a61cc26cce9f38c6428b2043b502ffa66cf406
3
+ metadata.gz: 4f851ca90e635f3f6ac942e875e89fb87670ec9d
4
+ data.tar.gz: de5b33718676163ed2d8177b1a7b887b59b33b92
5
5
  SHA512:
6
- metadata.gz: 9471823d8fcedf11584e256e35551b999aa7fefa2b845ce6325bb14929b29a12ab955520cf10d7acbf3d388ec726364744e136a4a75268f36dad56780cb28674
7
- data.tar.gz: ffd8473401383c0e8f3d2ff0659363795411f751d40690b852f3e340658fe1b55f5c10bacfd26e1ff6eade821fa2a7cae2c650bf4465db0a694a78cf5c61cf00
6
+ metadata.gz: 1f3153699f140a1e55ba3ab153b76a7ad435acc00cc0d2640b958eaf0364f36d24118bd678944e83ccc9cf36aef0172c097602c1ccd0a772ed4708d843f1e691
7
+ data.tar.gz: 8a4f3c15288c91e8387acf7b87e4ff7ec430d5d70993eccbba3ab605291f74dc69c0ed80dffbe376d3c14f748ba7fd206975447a3ef443c7a495a03b145ad2c1
data/Rakefile CHANGED
@@ -1 +1,12 @@
1
1
  require "bundler/gem_tasks"
2
+
3
+ require "rake/testtask"
4
+
5
+ desc "Run tests"
6
+ task :default => :spec
7
+
8
+ Rake::TestTask.new(:spec) do |test|
9
+ test.test_files = FileList["spec/**/*_spec.rb"]
10
+ test.libs << "spec"
11
+ test.verbose = true
12
+ end
@@ -19,4 +19,5 @@ Gem::Specification.new do |spec|
19
19
 
20
20
  spec.add_development_dependency "bundler", "~> 1.3"
21
21
  spec.add_development_dependency "rake"
22
+ spec.add_development_dependency "minitest", "~> 5.0.7"
22
23
  end
@@ -44,11 +44,16 @@ class Bound
44
44
  seed
45
45
  end
46
46
 
47
+ def method_missing(meth, *args, &blk)
48
+ attribute = meth.to_s.gsub(/=$/, '')
49
+ raise ArgumentError.new("Unknown attribute: #{attribute}")
50
+ end
51
+
47
52
  private
48
53
 
49
54
  def validate!
50
55
  self.class.attributes.each do |attribute|
51
- raise ArgumentError unless @hash.key?(attribute)
56
+ raise ArgumentError.new("Missing attribute: #{attribute}") unless @hash.key?(attribute)
52
57
  end
53
58
  end
54
59
 
@@ -72,7 +77,7 @@ class Bound
72
77
  begin
73
78
  h[attr] = object.public_send(attr)
74
79
  rescue NoMethodError
75
- raise ArgumentError.new(attr)
80
+ raise ArgumentError.new("Missing attribute: #{attr}")
76
81
  end
77
82
  h
78
83
  end
@@ -1,3 +1,3 @@
1
1
  class Bound
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -19,9 +19,11 @@ describe Bound do
19
19
  hash.delete :age
20
20
 
21
21
  [hash, object].each do |subject|
22
- assert_raises ArgumentError, subject.inspect do
22
+ exception = assert_raises ArgumentError, subject.inspect do
23
23
  User.new(subject)
24
24
  end
25
+
26
+ assert_match(/missing.+age/i, exception.message)
25
27
  end
26
28
  end
27
29
 
@@ -33,6 +35,17 @@ describe Bound do
33
35
  end
34
36
  end
35
37
 
38
+ it 'fails if attribute is unknown' do
39
+ hash[:gender] = "M"
40
+ subject = hash
41
+
42
+ exception = assert_raises ArgumentError, subject.inspect do
43
+ User.new(subject)
44
+ end
45
+
46
+ assert_match(/unknown.+gender/i, exception.message)
47
+ end
48
+
36
49
  describe 'optional attributes' do
37
50
  UserWithoutAge = Bound.new(:name, :optional => [:age])
38
51
 
@@ -14,18 +14,8 @@ require 'bound'
14
14
  #
15
15
  class HashObject
16
16
  def self.new(hash)
17
- build_class(hash.keys).new(hash)
18
- end
19
-
20
- def self.build_class(attributes)
21
- Class.new do
22
- attr_accessor(*attributes)
23
-
24
- def initialize(hash)
25
- hash.each do |attr, value|
26
- public_send "#{attr}=", value
27
- end
28
- end
29
- end
17
+ attributes = hash.keys
18
+ values = hash.values
19
+ Struct.new(*attributes).new(*values)
30
20
  end
31
21
  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.1
4
+ version: 0.0.2
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-19 00:00:00.000000000 Z
12
+ date: 2013-09-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -39,6 +39,20 @@ dependencies:
39
39
  - - '>='
40
40
  - !ruby/object:Gem::Version
41
41
  version: '0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: minitest
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ~>
47
+ - !ruby/object:Gem::Version
48
+ version: 5.0.7
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ~>
54
+ - !ruby/object:Gem::Version
55
+ version: 5.0.7
42
56
  description:
43
57
  email:
44
58
  - jh@neopoly.de