accessory 0.1.7 → 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/accessory/accessor.rb +6 -5
- data/lib/accessory/accessors/attribute_accessor.rb +2 -2
- data/lib/accessory/accessors/between_each_accessor.rb +1 -1
- data/lib/accessory/accessors/betwixt_accessor.rb +3 -2
- data/lib/accessory/accessors/first_accessor.rb +2 -2
- data/lib/accessory/accessors/last_accessor.rb +2 -2
- data/lib/accessory/accessors/subscript_accessor.rb +1 -1
- data/lib/accessory/lens.rb +1 -1
- data/lib/accessory/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: bad93b39fc1164c938ed170896bfc5d6ef0c7d157a443b05395ef835fcaf6706
|
4
|
+
data.tar.gz: ac0cdef27d42a339c3b640ee06c8231f4e724b2b2e541eb081bc37d33542fa35
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ae8c4170a783795b4e436232f1051c7bd3b0ef39132af63fcc0055c27df97eaabcd981f00a338f38bf0a343a582e30db1dc7b2cc4026f07d8dfa93d47177df8c
|
7
|
+
data.tar.gz: f78e0b73341624deb56871906d2dc33e5791a7514f3c6bd9f3db955c6f7e09e95621827d9a7978ec21f5fb7ff1fbbad764feb271e676525e957355e7dd7b6fe1
|
data/lib/accessory/accessor.rb
CHANGED
@@ -134,7 +134,8 @@ class Accessory::Accessor
|
|
134
134
|
# of the +get_result+s should replicate the data flow of {get}.
|
135
135
|
# * the +new_value+ should be used to *replace* or *overwrite* the result of
|
136
136
|
# this accessor's traversal within +data+. For example, in
|
137
|
-
# {SubscriptAccessor}, <tt>data[key] = new_value</tt> is
|
137
|
+
# {Accessors::SubscriptAccessor}, <tt>data[key] = new_value</tt> is
|
138
|
+
# executed.
|
138
139
|
#
|
139
140
|
# In the <tt>:pop</tt> command case:
|
140
141
|
# * the result of the traversal (*before* the yield) should be returned. This
|
@@ -142,7 +143,7 @@ class Accessory::Accessor
|
|
142
143
|
# traversal-results before feeding them into yield, in order to return them
|
143
144
|
# here.
|
144
145
|
# * the traversal-result should be *removed* from +data+. For example, in
|
145
|
-
# {SubscriptAccessor}, <tt>data.delete(key)</tt> is executed.
|
146
|
+
# {Accessors::SubscriptAccessor}, <tt>data.delete(key)</tt> is executed.
|
146
147
|
#
|
147
148
|
# The successor in the accessor chain will receive the yielded
|
148
149
|
# traversal-results as its own +data+.
|
@@ -195,9 +196,9 @@ class Accessory::Accessor
|
|
195
196
|
#
|
196
197
|
#
|
197
198
|
# For example, if your accessor operates on +Enumerable+ values (like
|
198
|
-
# {AllAccessor}), then this method should validate that the
|
199
|
-
# is +Enumerable+; and, if it isn't, return something that
|
200
|
-
# +Array+.
|
199
|
+
# {Accessors::AllAccessor}), then this method should validate that the
|
200
|
+
# +traversal_result+ is +Enumerable+; and, if it isn't, return something that
|
201
|
+
# is — e.g. an empty +Array+.
|
201
202
|
#
|
202
203
|
# This logic is used to replace invalid intermediate values (e.g. `nil`s and
|
203
204
|
# scalars) with containers during {Lens#put_in} et al.
|
@@ -8,8 +8,8 @@ require 'accessory/accessor'
|
|
8
8
|
# the getter/setter pair <tt>.foo</tt> and <tt>.foo=</tt>.
|
9
9
|
#
|
10
10
|
# The abstract "attribute" does not have to correspond to an actual
|
11
|
-
# +attr_accessor+; the
|
12
|
-
# named getter/setter methods exist on the receiver.
|
11
|
+
# +attr_accessor+; the AttributeAccessor will work as long as the
|
12
|
+
# relevant named getter/setter methods exist on the receiver.
|
13
13
|
#
|
14
14
|
# *Aliases*
|
15
15
|
# * {Access.attr}
|
@@ -5,7 +5,7 @@ require 'accessory/traversal_position/enumerable_before_offset'
|
|
5
5
|
# Traverses the positions "between" the elements of an +Enumerable+, including
|
6
6
|
# the positions at the "edges" (i.e. before the first, and after the last.)
|
7
7
|
#
|
8
|
-
#
|
8
|
+
# BetweenEachAccessor can be used with {Lens#put_in} to insert new
|
9
9
|
# elements into an Enumerable between the existing ones.
|
10
10
|
#
|
11
11
|
# *Aliases*
|
@@ -13,10 +13,11 @@ require 'accessory/traversal_position/enumerable_before_offset'
|
|
13
13
|
# The +offset+ in this accessor has equivalent semantics to the offset in
|
14
14
|
# <tt>Array#insert(offset, obj)</tt>.
|
15
15
|
#
|
16
|
-
# {BetwixtAccessor} can be used with {Lens#put_in} to insert new
|
16
|
+
# {Accessors::BetwixtAccessor} can be used with {Lens#put_in} to insert new
|
17
17
|
# elements into an Enumerable between the existing ones. If you want to extend
|
18
18
|
# an +Enumerable+ as you would with <tt>#push</tt> or <tt>#unshift</tt>, this
|
19
|
-
# accessor will have better behavior than using {SubscriptAccessor}
|
19
|
+
# accessor will have better behavior than using {Accessors::SubscriptAccessor}
|
20
|
+
# would.
|
20
21
|
#
|
21
22
|
# *Aliases*
|
22
23
|
# * {Access.betwixt}
|
@@ -4,8 +4,8 @@ require 'accessory/accessor'
|
|
4
4
|
# Traverses into the "first" element within an +Enumerable+, using
|
5
5
|
# <tt>#first</tt>.
|
6
6
|
#
|
7
|
-
# This accessor can be preferable to {SubscriptAccessor} for objects
|
8
|
-
# are not subscriptable, e.g.
|
7
|
+
# This accessor can be preferable to {Accessors::SubscriptAccessor} for objects
|
8
|
+
# that are not subscriptable, e.g. +Range+.
|
9
9
|
#
|
10
10
|
# *Aliases*
|
11
11
|
# * {Access.first}
|
@@ -4,8 +4,8 @@ require 'accessory/accessor'
|
|
4
4
|
# Traverses into the "last" element within an +Enumerable+, using
|
5
5
|
# <tt>#last</tt>.
|
6
6
|
#
|
7
|
-
# This accessor can be preferable to {SubscriptAccessor} for objects
|
8
|
-
# are not subscriptable, e.g.
|
7
|
+
# This accessor can be preferable to {Accessors::SubscriptAccessor} for objects
|
8
|
+
# that are not subscriptable, e.g. +Range+.
|
9
9
|
#
|
10
10
|
# *Aliases*
|
11
11
|
# * {Access.last}
|
@@ -29,7 +29,7 @@ require 'accessory/accessor'
|
|
29
29
|
# # default-constructs a Hash, not an Array
|
30
30
|
# [].lens[0][0].put_in(1) # => [{0=>1}]
|
31
31
|
#
|
32
|
-
# Other accessors ({FirstAccessor}, {BetwixtAccessor}, etc.) may fit your expectations more closely for +Array+ traversal.
|
32
|
+
# Other accessors ({Accessors::FirstAccessor}, {Accessors::BetwixtAccessor}, etc.) may fit your expectations more closely for +Array+ traversal.
|
33
33
|
|
34
34
|
class Accessory::Accessors::SubscriptAccessor < Accessory::Accessor
|
35
35
|
# @!visibility private
|
data/lib/accessory/lens.rb
CHANGED
@@ -164,7 +164,7 @@ class Accessory::Lens
|
|
164
164
|
# 1. the _old_ value(s) found after all traversals, and
|
165
165
|
# 2. the updated +subject+
|
166
166
|
def update_in(subject, &new_value_fn)
|
167
|
-
_, new_data = self.get_and_update_in(
|
167
|
+
_, new_data = self.get_and_update_in(subject){ |v| [nil, new_value_fn.call(v)] }
|
168
168
|
new_data
|
169
169
|
end
|
170
170
|
|
data/lib/accessory/version.rb
CHANGED