attr_extras 4.5.0 → 4.6.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,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3a8bcd34f935912a3cf97f5a31b39330e357aa61
4
- data.tar.gz: f99cb0a632963344367f906285cc572b913932a1
3
+ metadata.gz: 38b2b1b3e247d7f1dbc20e44110939f9ff6366e0
4
+ data.tar.gz: df85b55e2c60037a153f6127dc9758ce329b9b2b
5
5
  SHA512:
6
- metadata.gz: 796bdd29576ca722747c2b2508571f6ab60197741e1dbf91532f4f6cdcbcfcc478e81d3ffb41e72345a22d5319eb9e066879144b6eaf7624bd0dd6765223d5aa
7
- data.tar.gz: 5b0a456b2657f7a33823b98b864821ab8845296e63d459d661cce67d7d2b2a296208cb7097e34209bd4063510c79dc9f3906fbe8cd7ad7bce6265e1de7faca11
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
 
@@ -61,9 +61,11 @@ module AttrExtras
61
61
 
62
62
  alias_method :attr_accessor_initialize, :aattr_initialize
63
63
 
64
- def static_facade(method_name, *names)
65
- define_singleton_method(method_name) do |*values|
66
- new(*values).public_send(method_name)
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)
@@ -1,3 +1,3 @@
1
1
  module AttrExtras
2
- VERSION = "4.5.0"
2
+ VERSION = "4.6.0"
3
3
  end
@@ -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.5.0
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-03-08 00:00:00.000000000 Z
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.2.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.