attr_extras 4.5.0 → 4.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -0
- data/lib/attr_extras/explicit.rb +5 -3
- data/lib/attr_extras/version.rb +1 -1
- data/spec/attr_extras/static_facade_spec.rb +18 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 38b2b1b3e247d7f1dbc20e44110939f9ff6366e0
|
4
|
+
data.tar.gz: df85b55e2c60037a153f6127dc9758ce329b9b2b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c1a61d4507ca8ce8f60e0def7521cde84e6918025125f0573add4b3271b1edcd0cf831d7c9f34a37970951abe8051339ebe83b1e33aa9fcf9efa4b86e4f46731
|
7
|
+
data.tar.gz: 9c17ccb154eda8c4790654c80ab32a5ccd34e4dbf06dc31717e3b6511b8e8ee19d2370f50496b04beb17af582689c930e2eb77d1a753de9223a09deb753782f0
|
data/README.md
CHANGED
@@ -224,6 +224,8 @@ end
|
|
224
224
|
|
225
225
|
You don't have to specify arguments/readers if you don't want them: just `static_facade :tuesday?` is also valid.
|
226
226
|
|
227
|
+
You can specify multiple method names as long as they can share the same initializer arguments: `static_facade [:allow?, :deny?], :user, [:user_agent, :ip!]`
|
228
|
+
|
227
229
|
"Static façade" is the least bad name for this pattern we've come up with. Suggestions are welcome.
|
228
230
|
|
229
231
|
|
data/lib/attr_extras/explicit.rb
CHANGED
@@ -61,9 +61,11 @@ module AttrExtras
|
|
61
61
|
|
62
62
|
alias_method :attr_accessor_initialize, :aattr_initialize
|
63
63
|
|
64
|
-
def static_facade(
|
65
|
-
|
66
|
-
|
64
|
+
def static_facade(method_name_or_names, *names)
|
65
|
+
Array(method_name_or_names).each do |method_name|
|
66
|
+
define_singleton_method(method_name) do |*values|
|
67
|
+
new(*values).public_send(method_name)
|
68
|
+
end
|
67
69
|
end
|
68
70
|
|
69
71
|
pattr_initialize(*names)
|
data/lib/attr_extras/version.rb
CHANGED
@@ -26,4 +26,22 @@ describe Object, ".static_facade" do
|
|
26
26
|
|
27
27
|
assert klass.fooable?
|
28
28
|
end
|
29
|
+
|
30
|
+
it "accepts multiple method names" do
|
31
|
+
klass = Class.new do
|
32
|
+
static_facade [ :fooable?, :barable? ],
|
33
|
+
:foo
|
34
|
+
|
35
|
+
def fooable?
|
36
|
+
foo
|
37
|
+
end
|
38
|
+
|
39
|
+
def barable?
|
40
|
+
not foo
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
assert klass.fooable?(true)
|
45
|
+
assert klass.barable?(false)
|
46
|
+
end
|
29
47
|
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: 4.
|
4
|
+
version: 4.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Henrik Nyh
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2016-
|
13
|
+
date: 2016-06-16 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: minitest
|
@@ -113,7 +113,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
113
113
|
version: '0'
|
114
114
|
requirements: []
|
115
115
|
rubyforge_project:
|
116
|
-
rubygems_version: 2.
|
116
|
+
rubygems_version: 2.5.1
|
117
117
|
signing_key:
|
118
118
|
specification_version: 4
|
119
119
|
summary: Takes some boilerplate out of Ruby with methods like attr_initialize.
|