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.
- checksums.yaml +4 -4
- data/.rubocop.yml +5 -5
- data/.ruby-version +1 -1
- data/.travis.yml +1 -1
- data/CHANGELOG +67 -0
- data/Gemfile.lock +134 -126
- data/README.md +26 -0
- data/Rakefile +8 -1
- data/actionset.gemspec +2 -2
- data/lib/action_set.rb +8 -23
- data/lib/action_set/attribute_value.rb +7 -1
- data/lib/action_set/filter_instructions.rb +72 -0
- data/lib/action_set/helpers/helper_methods.rb +2 -1
- data/lib/action_set/helpers/pagination/record_description_for_helper.rb +20 -0
- data/lib/action_set/helpers/pagination/record_first_for_helper.rb +20 -0
- data/lib/action_set/helpers/pagination/record_last_for_helper.rb +26 -0
- data/lib/action_set/helpers/pagination/record_range_for_helper.rb +25 -0
- data/lib/action_set/helpers/pagination/record_size_for_helper.rb +9 -0
- data/lib/action_set/helpers/pagination/total_pages_for_helper.rb +3 -1
- data/lib/action_set/sort_instructions.rb +44 -0
- data/lib/active_set.rb +25 -2
- data/lib/active_set/active_record_set_instruction.rb +33 -32
- data/lib/active_set/attribute_instruction.rb +3 -3
- data/lib/active_set/enumerable_set_instruction.rb +13 -24
- data/lib/active_set/filtering/active_record/operators.rb +280 -0
- data/lib/active_set/filtering/active_record/query_column.rb +35 -0
- data/lib/active_set/filtering/active_record/query_value.rb +47 -0
- data/lib/active_set/filtering/active_record/set_instruction.rb +29 -0
- data/lib/active_set/filtering/active_record/strategy.rb +87 -0
- data/lib/active_set/filtering/constants.rb +349 -0
- data/lib/active_set/filtering/enumerable/operators.rb +308 -0
- data/lib/active_set/filtering/enumerable/set_instruction.rb +98 -0
- data/lib/active_set/filtering/enumerable/strategy.rb +90 -0
- data/lib/active_set/filtering/operation.rb +5 -8
- data/lib/active_set/paginating/active_record_strategy.rb +0 -2
- data/lib/active_set/sorting/active_record_strategy.rb +27 -3
- data/lib/active_set/sorting/enumerable_strategy.rb +12 -2
- data/lib/active_set/sorting/operation.rb +1 -2
- data/lib/helpers/flatten_keys_of.rb +53 -0
- data/lib/helpers/transform_to_sortable_numeric.rb +3 -3
- metadata +26 -13
- data/lib/active_set/filtering/active_record_strategy.rb +0 -85
- data/lib/active_set/filtering/enumerable_strategy.rb +0 -79
- data/lib/helpers/throws.rb +0 -19
- data/lib/patches/core_ext/hash/flatten_keys.rb +0 -58
data/lib/helpers/throws.rb
DELETED
@@ -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
|