attr_extras 2.2.3 → 2.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -13
- data/README.md +5 -0
- data/lib/attr_extras.rb +9 -1
- data/lib/attr_extras/attr_initialize.rb +1 -1
- data/lib/attr_extras/version.rb +1 -1
- data/spec/attr_implement_spec.rb +23 -0
- metadata +12 -10
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
ZTVhMmQ4NDc3YTExMjY1Y2NkYzkzNjk5ZGRmOWM4OTVhMmQwODlkMA==
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: bfeb7ee3f02c3e7a249a3a76041fa4faf1604b36
|
4
|
+
data.tar.gz: f976af63159f1beaa0f951652a8ea15220c9b650
|
7
5
|
SHA512:
|
8
|
-
metadata.gz:
|
9
|
-
|
10
|
-
ZTEwYTRkZTJmZTcyNWYzZWEzMWQyYmZkMzhiZjc5ZTZjMjM4ODM2NjJjODhk
|
11
|
-
OWRkZTUyYjk0Y2M1ZTEzOWMxZjQyMjk2ODA0NjdkMGRiYWQyMzg=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
MTc0YWQ0Y2EwODQwOTczOWMwNGY3MTMxMDE5OWZmYWNkMTgzNDFmYTUxZDA4
|
14
|
-
Y2M1YjU3ZTcwYzkwMmI4NGNiM2ZhNWNiMGY1ODE4ZmEyZWQ4OTE3MWE5OGNj
|
15
|
-
ZGE2ODUyYzM4MTAzMDIwYzVhZmNlYzUzMjJiNjE5Yzg4Yzg4MWI=
|
6
|
+
metadata.gz: 49df99f90b8667b4926a30af53e23e50a2327e0305cbf0c81956fba1223773c46e3714e3c29e70cf8a049c21398edd6adb18abe562048346e72baa1a3c7eb7e9
|
7
|
+
data.tar.gz: c3875dd5d15e08ebaca8941a7624839dca8fcbb4c0acaf607108aae231303204c17d076b9ff0bf2beb12477d78fc0cb30b81e70820723211d3f61e8ac2915b7b
|
data/README.md
CHANGED
@@ -141,6 +141,10 @@ Defines query methods like `foo?`, which is true if (and only if) `foo_id` is tr
|
|
141
141
|
|
142
142
|
Defines query methods like `foo?`, which is true if (and only if) `foo` is truthy.
|
143
143
|
|
144
|
+
### `attr_implement :foo, :bar`<br>
|
145
|
+
|
146
|
+
Defines methods `foo` and `bar` that raise e.g. `"Implement a 'foo' method"`, suitable for abstract base classes.
|
147
|
+
|
144
148
|
|
145
149
|
## Philosophy
|
146
150
|
|
@@ -195,6 +199,7 @@ Or to see warnings (try not to have any):
|
|
195
199
|
* [Joakim Kolsjö](https://github.com/joakimk)
|
196
200
|
* [Victor Arias](https://github.com/victorarias)
|
197
201
|
* [Teo Ljungberg](https://github.com/teoljungberg)
|
202
|
+
* [Kim Persson](https://github.com/lavinia)
|
198
203
|
|
199
204
|
|
200
205
|
## License
|
data/lib/attr_extras.rb
CHANGED
@@ -32,7 +32,7 @@ module AttrExtras
|
|
32
32
|
alias_method :eql?, :==
|
33
33
|
|
34
34
|
define_method(:hash) do
|
35
|
-
[self.class, *names.map { |attr| public_send(attr) }].hash
|
35
|
+
[ self.class, *names.map { |attr| public_send(attr) } ].hash
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
@@ -61,6 +61,14 @@ module AttrExtras
|
|
61
61
|
def attr_id_query(*names)
|
62
62
|
AttrQuery.define_with_suffix(self, "_id", *names)
|
63
63
|
end
|
64
|
+
|
65
|
+
def attr_implement(*names)
|
66
|
+
names.each do |name|
|
67
|
+
define_method(name) do |*_|
|
68
|
+
raise "Implement a '#{name}' method"
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
64
72
|
end
|
65
73
|
end
|
66
74
|
|
data/lib/attr_extras/version.rb
CHANGED
@@ -0,0 +1,23 @@
|
|
1
|
+
require_relative "spec_helper"
|
2
|
+
|
3
|
+
describe Object, ".attr_implement" do
|
4
|
+
it "creates methods that raise" do
|
5
|
+
klass = Class.new do
|
6
|
+
attr_implement :foo, :bar
|
7
|
+
end
|
8
|
+
|
9
|
+
example = klass.new
|
10
|
+
exception = lambda { example.foo }.must_raise RuntimeError
|
11
|
+
exception.message.must_equal "Implement a 'foo' method"
|
12
|
+
end
|
13
|
+
|
14
|
+
it "accepts any number of arguments" do
|
15
|
+
klass = Class.new do
|
16
|
+
attr_implement :foo
|
17
|
+
end
|
18
|
+
|
19
|
+
example = klass.new
|
20
|
+
exception = lambda { example.foo(1, 2, 3) }.must_raise RuntimeError
|
21
|
+
exception.message.must_equal "Implement a 'foo' method"
|
22
|
+
end
|
23
|
+
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: 2.
|
4
|
+
version: 2.3.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-
|
13
|
+
date: 2014-05-15 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
|
@@ -48,6 +48,7 @@ files:
|
|
48
48
|
- script/test
|
49
49
|
- spec/attr_extras_spec.rb
|
50
50
|
- spec/attr_id_query_spec.rb
|
51
|
+
- spec/attr_implement_spec.rb
|
51
52
|
- spec/attr_initialize_spec.rb
|
52
53
|
- spec/attr_private_spec.rb
|
53
54
|
- spec/attr_query_spec.rb
|
@@ -66,23 +67,24 @@ require_paths:
|
|
66
67
|
- lib
|
67
68
|
required_ruby_version: !ruby/object:Gem::Requirement
|
68
69
|
requirements:
|
69
|
-
- -
|
70
|
+
- - ">="
|
70
71
|
- !ruby/object:Gem::Version
|
71
72
|
version: '0'
|
72
73
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
74
|
requirements:
|
74
|
-
- -
|
75
|
+
- - ">="
|
75
76
|
- !ruby/object:Gem::Version
|
76
77
|
version: '0'
|
77
78
|
requirements: []
|
78
79
|
rubyforge_project:
|
79
|
-
rubygems_version: 2.2.
|
80
|
+
rubygems_version: 2.2.2
|
80
81
|
signing_key:
|
81
82
|
specification_version: 4
|
82
83
|
summary: Takes some boilerplate out of Ruby with methods like attr_initialize.
|
83
84
|
test_files:
|
84
85
|
- spec/attr_extras_spec.rb
|
85
86
|
- spec/attr_id_query_spec.rb
|
87
|
+
- spec/attr_implement_spec.rb
|
86
88
|
- spec/attr_initialize_spec.rb
|
87
89
|
- spec/attr_private_spec.rb
|
88
90
|
- spec/attr_query_spec.rb
|