Class: Scopie::Base
- Inherits:
-
Object
- Object
- Scopie::Base
- Defined in:
- lib/scopie/base.rb
Constant Summary collapse
- TRUE_VALUES =
['true', true, '1', 1].freeze
Class Method Summary collapse
Instance Method Summary collapse
- #apply_scopes(target, hash, method = nil) ⇒ Object
- #current_scopes(hash, method = nil) ⇒ Object
- #scopes_configuration ⇒ Object
Class Method Details
.has_scope(*scopes, **options) ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/scopie/base.rb', line 15 def self.has_scope(*scopes, **) @scopes_configuration ||= {} scopes.each do |scope| @scopes_configuration[scope.to_sym] = end end |
.scopes_configuration ⇒ Object
7 8 9 |
# File 'lib/scopie/base.rb', line 7 def self.scopes_configuration instance_variable_get(:@scopes_configuration) || {} end |
Instance Method Details
#apply_scopes(target, hash, method = nil) ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/scopie/base.rb', line 23 def apply_scopes(target, hash, method = nil) current_scopes(hash, method).each do |scope_name, value| target = apply_scope(scope_name, target, value, hash) end target end |
#current_scopes(hash, method = nil) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/scopie/base.rb', line 31 def current_scopes(hash, method = nil) scopes = scopes_configuration.map do |scope_name, | value = scope_value(scope_name, , hash) next unless scope_applicable?(value, , method) [scope_name, coerce_value_type(value, [:type])] end scopes.compact! scopes.to_h end |
#scopes_configuration ⇒ Object
11 12 13 |
# File 'lib/scopie/base.rb', line 11 def scopes_configuration self.class.scopes_configuration end |