order_already 0.2.0 → 0.2.1

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
  SHA256:
3
- metadata.gz: c26d17f72e31fe01a89459e031b394237dfe163d8c5548307cc7b00308115175
4
- data.tar.gz: 0c1b6a4e25e973ff90a2dcd05cc21b9b3267a9110f762c15707cee9d4b7e10a8
3
+ metadata.gz: 1dab15b63f8b14d65dbbcb5f6fe968a03330e88ef48d8104233a90fa374a5087
4
+ data.tar.gz: fd1f5a1f2d9895c5012e280f40405b07c7c7729a98aa433b9ba9460f1bf0bd90
5
5
  SHA512:
6
- metadata.gz: 640aae2c6f8f6c678afe164aa37044afad6192f88ea042e7aa50b431e62258cd267a95368ab82bbcb2a28845e57be939d7a663f8e8995bb532dc038d5d8c0c54
7
- data.tar.gz: 6400c35df376c1767b59d7a8bbab52a8554917c51c84fdd4592a09b6bdf703d344e2765824d6a7f1ab24d1d96b37a62045a74bd03906ab981ae302c9a2e53719
6
+ metadata.gz: 7b06788255b18b24895117f7ff9dfd605ac67e85c5d60fb934dbb79fdcecea09b399510d74fc2327d0b0fbd9bd5b8643186940e3488d52c86c4593391084c8d4
7
+ data.tar.gz: '09010bdfeae1a452fb97c178c44f9ea0143f3df3b532f7684c3baf113edbb36295a51bf611f8066ebd38a95b7f3d782a4fc260a805f76b6161014348e4a32468'
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- order_already (0.1.0)
4
+ order_already (0.2.0)
5
5
  rails-html-sanitizer (~> 1.4)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -47,6 +47,8 @@ class GenericWork < ActiveFedora::Base
47
47
  end
48
48
  ```
49
49
 
50
+ As of v0.2.0, the `OrderAlready.for` method takes a `:serializer` keyword. By default this is the preserve the order of the input serializers.
51
+
50
52
  ## Development
51
53
 
52
54
  After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module OrderAlready
4
- VERSION = "0.2.0"
4
+ VERSION = "0.2.1"
5
5
  end
data/lib/order_already.rb CHANGED
@@ -17,9 +17,10 @@ module OrderAlready
17
17
  #
18
18
  # @param attributes [Array<Symbol>] the name of the attributes/properties you want to order.
19
19
  # @param serializer [#serialize, #deserialize] the service class responsible for serializing the
20
- # data. Want to auto-alphabetize? Inject a new serializer.
20
+ # data. Want to auto-alphabetize? Use a different serializer than the default.
21
21
  #
22
- # @return [Module] a module that wraps the attr_accessor methods for the given :attributes.
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
24
  #
24
25
  # @note In testing, you need to use `prepend` instead of `include`; but that may be a function of
25
26
  # my specs.
@@ -34,7 +35,13 @@ module OrderAlready
34
35
  # end
35
36
  # prepend OrderAlready.for(:creators)
36
37
  # end
37
- def self.for(*attributes, serializer: StringSerializer)
38
+ #
39
+ # class OtherRecord
40
+ # attr_accessor :subjects
41
+ # # Assumes there's an Alphabetizer constant that responds to .serialize and .deserialize
42
+ # prepend OrderAlready.for(:subjects, serializer: Alphabetizer)
43
+ # end
44
+ def self.for(*attributes, serializer: InputOrderSerializer)
38
45
  # By creating a module, we have access to `super`.
39
46
  Module.new do
40
47
  attributes.each do |attribute|
@@ -49,10 +56,14 @@ module OrderAlready
49
56
  end
50
57
  end
51
58
 
52
- module StringSerializer
53
- # defaults
59
+ # This serializer preserves the input order regardless of underlying persistence order.
60
+ #
61
+ # The two public methods are {.deserialize} and {.serialize}.
62
+ module InputOrderSerializer
54
63
  TOKEN_DELIMITER = '~'
55
64
 
65
+ # @api public
66
+ #
56
67
  # Convert a serialized array to a normal array of values.
57
68
  # @param arr [Array]
58
69
  # @return [Array]
@@ -64,6 +75,8 @@ module OrderAlready
64
75
  end
65
76
  end
66
77
 
78
+ # @api public
79
+ #
67
80
  # Serialize a normal array of values to an array of ordered values
68
81
  #
69
82
  # @param arr [Array]
@@ -93,7 +106,8 @@ module OrderAlready
93
106
 
94
107
  # Sort an array of serialized values using the index token to determine the order
95
108
  def self.sort(arr)
96
- # Hack to force a stable sort; see https://stackoverflow.com/questions/15442298/is-sort-in-ruby-stable
109
+ # Hack to force a stable sort; see
110
+ # https://stackoverflow.com/questions/15442298/is-sort-in-ruby-stable
97
111
  n = 0
98
112
  arr.sort_by { |val| [get_index(val), n += 1] }
99
113
  end
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.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Friesen