chainable_accessor 0.1.0 → 0.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 +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +2 -1
- data/lib/chainable_accessor.rb +2 -2
- data/lib/chainable_accessor/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 181322f251c320410b5cffd05ec67554c69861c2e951bb087ff17ef29b2ac532
|
4
|
+
data.tar.gz: e5592e81b480fff56186bf14cbe2bb283dbb23860649d87e60d478efee4f923e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c6edc28de6d603cefc0079ebabbeac9afd78df539e73334639c1af485ad859ca94aed796bd775574e4c3920907e47e6932dd2fd2a036f42fec83b20802c485ff
|
7
|
+
data.tar.gz: 555355c7cf960055d3611bc1a7501325b9e10f773c99c6d8b72480bf146e32c99db1667012a91d09c6928c2660fedd0e8dec745d7c4c0b7a3029cae4a6c7ab2e
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -23,8 +23,9 @@ Or install it yourself as:
|
|
23
23
|
|
24
24
|
```ruby
|
25
25
|
class Search
|
26
|
-
attr_accessor :word, :page, :sort
|
26
|
+
attr_accessor :word, :page, :sort, :foo, :bar
|
27
27
|
chainable_accessor :word, :page, :sort
|
28
|
+
chainable_accessor :foo, :bar, immutable: true
|
28
29
|
end
|
29
30
|
|
30
31
|
Search.new.word('foo').page(1).sort(:released_at)
|
data/lib/chainable_accessor.rb
CHANGED
@@ -3,13 +3,13 @@
|
|
3
3
|
require_relative 'chainable_accessor/version'
|
4
4
|
|
5
5
|
module ChainableAccessor
|
6
|
-
def chainable_accessor(*attributes)
|
6
|
+
def chainable_accessor(*attributes, immutable: false)
|
7
7
|
mod = Module.new do
|
8
8
|
attributes.each do |name|
|
9
9
|
define_method name do |val = nil|
|
10
10
|
return super() unless val
|
11
11
|
|
12
|
-
tap { |x| x.send("#{name}=", val) }
|
12
|
+
(immutable ? dup : self).tap { |x| x.send("#{name}=", val) }
|
13
13
|
end
|
14
14
|
end
|
15
15
|
end
|