actionset 0.8.1 → 0.11.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.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +5 -5
  3. data/.ruby-version +1 -1
  4. data/.travis.yml +1 -1
  5. data/CHANGELOG +67 -0
  6. data/Gemfile.lock +134 -126
  7. data/README.md +26 -0
  8. data/Rakefile +8 -1
  9. data/actionset.gemspec +2 -2
  10. data/lib/action_set.rb +8 -23
  11. data/lib/action_set/attribute_value.rb +7 -1
  12. data/lib/action_set/filter_instructions.rb +72 -0
  13. data/lib/action_set/helpers/helper_methods.rb +2 -1
  14. data/lib/action_set/helpers/pagination/record_description_for_helper.rb +20 -0
  15. data/lib/action_set/helpers/pagination/record_first_for_helper.rb +20 -0
  16. data/lib/action_set/helpers/pagination/record_last_for_helper.rb +26 -0
  17. data/lib/action_set/helpers/pagination/record_range_for_helper.rb +25 -0
  18. data/lib/action_set/helpers/pagination/record_size_for_helper.rb +9 -0
  19. data/lib/action_set/helpers/pagination/total_pages_for_helper.rb +3 -1
  20. data/lib/action_set/sort_instructions.rb +44 -0
  21. data/lib/active_set.rb +25 -2
  22. data/lib/active_set/active_record_set_instruction.rb +33 -32
  23. data/lib/active_set/attribute_instruction.rb +3 -3
  24. data/lib/active_set/enumerable_set_instruction.rb +13 -24
  25. data/lib/active_set/filtering/active_record/operators.rb +280 -0
  26. data/lib/active_set/filtering/active_record/query_column.rb +35 -0
  27. data/lib/active_set/filtering/active_record/query_value.rb +47 -0
  28. data/lib/active_set/filtering/active_record/set_instruction.rb +29 -0
  29. data/lib/active_set/filtering/active_record/strategy.rb +87 -0
  30. data/lib/active_set/filtering/constants.rb +349 -0
  31. data/lib/active_set/filtering/enumerable/operators.rb +308 -0
  32. data/lib/active_set/filtering/enumerable/set_instruction.rb +98 -0
  33. data/lib/active_set/filtering/enumerable/strategy.rb +90 -0
  34. data/lib/active_set/filtering/operation.rb +5 -8
  35. data/lib/active_set/paginating/active_record_strategy.rb +0 -2
  36. data/lib/active_set/sorting/active_record_strategy.rb +27 -3
  37. data/lib/active_set/sorting/enumerable_strategy.rb +12 -2
  38. data/lib/active_set/sorting/operation.rb +1 -2
  39. data/lib/helpers/flatten_keys_of.rb +53 -0
  40. data/lib/helpers/transform_to_sortable_numeric.rb +3 -3
  41. metadata +26 -13
  42. data/lib/active_set/filtering/active_record_strategy.rb +0 -85
  43. data/lib/active_set/filtering/enumerable_strategy.rb +0 -79
  44. data/lib/helpers/throws.rb +0 -19
  45. data/lib/patches/core_ext/hash/flatten_keys.rb +0 -58
@@ -1,19 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Returns a Boolean for whether the block raises the Exception expected
4
- #
5
- # throws?(StandardError) { raise }
6
- # => true
7
- # throws?(NameError) { raise NameError }
8
- # => true
9
- # throws?(NoMethodError) { raise NameError }
10
- # => false
11
- # throws?(StandardError) { 'foo' }
12
- # => false
13
-
14
- def throws?(exception)
15
- yield
16
- false
17
- rescue StandardError => e
18
- e.is_a? exception
19
- end
@@ -1,58 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'active_support/core_ext/array/wrap'
4
-
5
- class Hash
6
- # Returns a flat hash where all nested keys are collapsed into an array of keys.
7
- #
8
- # hash = { person: { name: { first: 'Rob' }, age: '28' } }
9
- # hash.flatten_keys_to_array
10
- # => {[:person, :name, :first] => "Rob", [:person, :age]=>"28" }
11
- def flatten_keys_to_array
12
- _flatten_keys(self)
13
- end
14
- alias flatten_keys flatten_keys_to_array
15
-
16
- # Returns a flat hash where all nested keys are collapsed into a dot-separated string of keys.
17
- #
18
- # hash = { person: { name: { first: 'Rob' }, age: '28' } }
19
- # hash.flatten_keys_to_dotpath
20
- # => { 'person.name.first' => "Rob", 'person.age'=>"28" }
21
- def flatten_keys_to_dotpath
22
- _flatten_keys(self, ->(*keys) { keys.join('.') })
23
- end
24
-
25
- # Returns a flat hash where all nested keys are collapsed into a dast-separated string of keys.
26
- #
27
- # hash = { person: { name: { first: 'Rob' }, age: '28' } }
28
- # hash.flatten_keys_to_html_attribute
29
- # => { 'person-name-first' => "Rob", 'person-age'=>"28" }
30
- def flatten_keys_to_html_attribute
31
- _flatten_keys(self, ->(*keys) { keys.join('-') })
32
- end
33
-
34
- # Returns a flat hash where all nested keys are collapsed into a string of keys
35
- # fitting the Rails request param pattern.
36
- #
37
- # hash = { person: { name: { first: 'Rob' }, age: '28' } }
38
- # hash.flatten_keys_to_rails_param
39
- # => { 'person[name][first]' => "Rob", 'person[age]'=>"28" }
40
- def flatten_keys_to_rails_param
41
- _flatten_keys(self, ->(*keys) { keys.map(&:to_s).reduce { |memo, key| memo + "[#{key}]" } })
42
- end
43
-
44
- private
45
-
46
- # refactored from https://stackoverflow.com/a/23861946/2884386
47
- def _flatten_keys(input, keypath_gen = ->(*keys) { keys }, keys = [], output = {})
48
- if input.is_a? Hash
49
- input.each { |k, v| _flatten_keys(v, keypath_gen, keys + Array(k), output) }
50
- # elsif input.is_a? Array
51
- # input.each_with_index { |v, i| _flatten_keys(v, keypath_gen, keys + Array(i), output) }
52
- else
53
- return output.merge!(keypath_gen.call(*keys) => input)
54
- end
55
-
56
- output
57
- end
58
- end