attr_extras 3.1.0 → 3.2.0

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,15 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 52ef09869d3ebdb635964d77234b8bf806b85370
4
- data.tar.gz: 3ae234b7c52e1e766cb1399d44c09f5cfc7ee82a
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ZWFjODUyMWM5ZDQwYTllYzlkYWU4YjkwNzBkOWQ1YjY0NTE5MWY0ZQ==
5
+ data.tar.gz: !binary |-
6
+ NzI4N2YyZjcwN2ZkZDIzMmIyN2I2NmI3NDJjMGNlZTQyNjZkOGNmYw==
5
7
  SHA512:
6
- metadata.gz: 926fdc5d339f40c481cfec0fbb0a20bb7c11ffcc3fe4206fde1c25e3d6183834e04c4bec247c3c89672f22f6d48a0adb1454c93a98b734b17029503c9fffdb98
7
- data.tar.gz: d6040789a8f309c42a5fa15f46c7168ca0a65975d4a15989bd2b0ad723c8d0de9636b7101ca05e510dd869d9a94855c5e3740a2bee72d4e055fe33679a066eba
8
+ metadata.gz: !binary |-
9
+ NTUxMDVlN2I2NzI4NzY4MjBkMGM4OWQ0OGM5M2NjNGRkYzdiNzRiOWNiYzQ5
10
+ YTEyZTFhMjkxNjg3YTU2ZWJkMTgxNjU0OTU5NjcxNzY2YjYzODA0NTNlZmY4
11
+ MzYxZTc2ZTE5YzdiMjg1OTEzMmE1ODNmYzJjYmQ5OTkxMzZiODI=
12
+ data.tar.gz: !binary |-
13
+ YmRlYTAwYWQzMmJiODA2ZTk5YzEyMDVkNGVmY2JiODI5MGUxYTAxNWQzNDIx
14
+ MjAyZWM3OTUwOWMzN2Y0NDkxZjhkOGYwYmM0ZmNjM2JhMTg0MDQ1ZGM3NGQw
15
+ ZmE2YzM1MGE2ODU2YTExZGZmNGM5NmZhYzI3YzgwMTFjODNjMzQ=
data/lib/attr_extras.rb CHANGED
@@ -66,17 +66,23 @@ module AttrExtras
66
66
  arg_names = names.last.is_a?(Array) ? names.pop : []
67
67
  arity = arg_names.length
68
68
 
69
- names.each do |name|
70
- define_method(name) do |*args|
71
- provided_arity = args.length
72
-
73
- if provided_arity != arity
74
- raise ArgumentError, "wrong number of arguments (#{provided_arity} for #{arity})"
69
+ mod = Module.new do
70
+ define_method :method_missing do |name, *args|
71
+ if names.include?(name)
72
+ provided_arity = args.length
73
+
74
+ if provided_arity != arity
75
+ raise ArgumentError, "wrong number of arguments (#{provided_arity} for #{arity})"
76
+ end
77
+
78
+ raise "Implement a '#{name}(#{arg_names.join(", ")})' method"
79
+ else
80
+ super(name, *args)
75
81
  end
76
-
77
- raise "Implement a '#{name}(#{arg_names.join(", ")})' method"
78
82
  end
79
83
  end
84
+
85
+ include mod
80
86
  end
81
87
  end
82
88
  end
@@ -1,3 +1,3 @@
1
1
  module AttrExtras
2
- VERSION = "3.1.0"
2
+ VERSION = "3.2.0"
3
3
  end
@@ -23,4 +23,34 @@ describe Object, ".attr_implement" do
23
23
 
24
24
  lambda { example.foo }.must_raise ArgumentError
25
25
  end
26
+
27
+ it "does not raise if method is implemented in a subclass" do
28
+ klass = Class.new do
29
+ attr_implement :foo
30
+ end
31
+
32
+ subklass = Class.new(klass) do
33
+ def foo
34
+ "bar"
35
+ end
36
+ end
37
+
38
+ subklass.new.foo.must_equal "bar"
39
+ end
40
+
41
+ # E.g. Active Record defines column query methods like "admin?"
42
+ # higher up in the ancestor chain.
43
+ it "does not raise if method is implemented in a superclass" do
44
+ superklass = Class.new do
45
+ def foo
46
+ "bar"
47
+ end
48
+ end
49
+
50
+ klass = Class.new(superklass) do
51
+ attr_implement :foo
52
+ end
53
+
54
+ klass.new.foo.must_equal "bar"
55
+ end
26
56
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: attr_extras
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.0
4
+ version: 3.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henrik Nyh
@@ -10,20 +10,20 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2014-09-12 00:00:00.000000000 Z
13
+ date: 2015-01-10 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rake
17
17
  requirement: !ruby/object:Gem::Requirement
18
18
  requirements:
19
- - - ">="
19
+ - - ! '>='
20
20
  - !ruby/object:Gem::Version
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  requirements:
26
- - - ">="
26
+ - - ! '>='
27
27
  - !ruby/object:Gem::Version
28
28
  version: '0'
29
29
  description:
@@ -33,9 +33,9 @@ executables: []
33
33
  extensions: []
34
34
  extra_rdoc_files: []
35
35
  files:
36
- - ".gitignore"
37
- - ".rvmrc"
38
- - ".travis.yml"
36
+ - .gitignore
37
+ - .rvmrc
38
+ - .travis.yml
39
39
  - Gemfile
40
40
  - README.md
41
41
  - Rakefile
@@ -67,12 +67,12 @@ require_paths:
67
67
  - lib
68
68
  required_ruby_version: !ruby/object:Gem::Requirement
69
69
  requirements:
70
- - - ">="
70
+ - - ! '>='
71
71
  - !ruby/object:Gem::Version
72
72
  version: '0'
73
73
  required_rubygems_version: !ruby/object:Gem::Requirement
74
74
  requirements:
75
- - - ">="
75
+ - - ! '>='
76
76
  - !ruby/object:Gem::Version
77
77
  version: '0'
78
78
  requirements: []