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