Class: ReeMapper::FieldsFilter
- Inherits:
-
Object
- Object
- ReeMapper::FieldsFilter
show all
- Defined in:
- lib/ree_lib/packages/ree_mapper/package/ree_mapper/fields_filter.rb
Defined Under Namespace
Classes: ExceptStrategy, OnlyStrategy
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(strategy, nested_fields_filters) ⇒ FieldsFilter
Returns a new instance of FieldsFilter.
82
83
84
85
|
# File 'lib/ree_lib/packages/ree_mapper/package/ree_mapper/fields_filter.rb', line 82
def initialize(strategy, nested_fields_filters)
@strategy = strategy
@nested_fields_filters = nested_fields_filters
end
|
Class Method Details
.build(only, except) ⇒ Object
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
# File 'lib/ree_lib/packages/ree_mapper/package/ree_mapper/fields_filter.rb', line 62
def self.build(only, except)
strategy = if !only.nil?
OnlyStrategy.new(only, except)
elsif !except.nil?
ExceptStrategy.new(except)
else
return nil
end
nested_fields_filters = {}
only = only&.select { _1.is_a? Hash }&.reduce(&:merge)
except = except&.select { _1.is_a? Hash }&.reduce(&:merge)
only&.each { nested_fields_filters[_1] = build(_2, except&.dig(_1)) }
except&.each { nested_fields_filters[_1] ||= build(nil, _2) }
new(strategy, nested_fields_filters)
end
|
Instance Method Details
#allow?(field) ⇒ Boolean
87
88
89
|
# File 'lib/ree_lib/packages/ree_mapper/package/ree_mapper/fields_filter.rb', line 87
def allow?(field)
strategy.allow?(field)
end
|
#filter_for(field) ⇒ Object
91
92
93
|
# File 'lib/ree_lib/packages/ree_mapper/package/ree_mapper/fields_filter.rb', line 91
def filter_for(field)
nested_fields_filters[field]
end
|