order_already 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1dab15b63f8b14d65dbbcb5f6fe968a03330e88ef48d8104233a90fa374a5087
4
- data.tar.gz: fd1f5a1f2d9895c5012e280f40405b07c7c7729a98aa433b9ba9460f1bf0bd90
3
+ metadata.gz: 06d0792edcb48d855dd6d7fe7f7e7bd28ee198f6144a816e4b7594f49ea7fe32
4
+ data.tar.gz: bc0bb4eafc7c7f01bdbb90e3a5ab20b59abc74f797509f0da4f592ba946ca628
5
5
  SHA512:
6
- metadata.gz: 7b06788255b18b24895117f7ff9dfd605ac67e85c5d60fb934dbb79fdcecea09b399510d74fc2327d0b0fbd9bd5b8643186940e3488d52c86c4593391084c8d4
7
- data.tar.gz: '09010bdfeae1a452fb97c178c44f9ea0143f3df3b532f7684c3baf113edbb36295a51bf611f8066ebd38a95b7f3d782a4fc260a805f76b6161014348e4a32468'
6
+ metadata.gz: 57752a7bf98a638194b27db452a8028e30cfe94e2490972ee3b9164e72c3e20e6fbb3db4db9c1b6e3a1987259daf29e69b78657578a42342d68377d11e127a50
7
+ data.tar.gz: 16d4471e24105b2641ff0640963e3de6a2eff56dc84e0ea104415b1b4cbbe77ab146fcb71df6938f60f4bf1158b5fcf0bdee2d7e2c22939a8209669c83455d29
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- order_already (0.2.0)
4
+ order_already (0.2.1)
5
5
  rails-html-sanitizer (~> 1.4)
6
6
 
7
7
  GEM
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module OrderAlready
4
- VERSION = "0.2.1"
4
+ VERSION = "0.3.0"
5
5
  end
data/lib/order_already.rb CHANGED
@@ -20,7 +20,8 @@ module OrderAlready
20
20
  # data. Want to auto-alphabetize? Use a different serializer than the default.
21
21
  #
22
22
  # @return [Module] a module that wraps the attr_accessor methods for the given :attributes. In
23
- # using a module, we have access to `super`; which is super convenient!
23
+ # using a module, we have access to `super`; which is super convenient! The module will
24
+ # also add a `#attribute_is_ordered_already?` method.
24
25
  #
25
26
  # @note In testing, you need to use `prepend` instead of `include`; but that may be a function of
26
27
  # my specs.
@@ -42,9 +43,13 @@ module OrderAlready
42
43
  # prepend OrderAlready.for(:subjects, serializer: Alphabetizer)
43
44
  # end
44
45
  def self.for(*attributes, serializer: InputOrderSerializer)
46
+ # Capturing the named attributes to create a local binding; this helps ensure we have that
47
+ # available in the later :attribute_is_ordered_already? method definition.
48
+ ordered_attributes = attributes.map(&:to_sym)
49
+
45
50
  # By creating a module, we have access to `super`.
46
51
  Module.new do
47
- attributes.each do |attribute|
52
+ ordered_attributes.each do |attribute|
48
53
  define_method(attribute) do
49
54
  serializer.deserialize(super())
50
55
  end
@@ -53,6 +58,10 @@ module OrderAlready
53
58
  super(serializer.serialize(values))
54
59
  end
55
60
  end
61
+
62
+ define_method(:attribute_is_ordered_already?) do |attribute|
63
+ ordered_attributes.include?(attribute.to_sym)
64
+ end
56
65
  end
57
66
  end
58
67
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: order_already
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Friesen
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2022-11-19 00:00:00.000000000 Z
12
+ date: 2023-03-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails-html-sanitizer