Class: Scopie::Base
- Inherits:
-
Object
- Object
- Scopie::Base
- Defined in:
- lib/scopie/base.rb
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
13 14 15 16 17 18 19 |
# File 'lib/scopie/base.rb', line 13 def self.has_scope(*scopes, **) @scopes_configuration ||= {} scopes.each do |scope| @scopes_configuration[scope.to_sym] = end end |
.scopes_configuration ⇒ Object
5 6 7 |
# File 'lib/scopie/base.rb', line 5 def self.scopes_configuration instance_variable_get(:@scopes_configuration) || {} end |
Instance Method Details
#apply_scopes(target, hash, method = nil) ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/scopie/base.rb', line 21 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
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/scopie/base.rb', line 29 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, value.coerced] end scopes.compact! scopes.to_h end |
#scopes_configuration ⇒ Object
9 10 11 |
# File 'lib/scopie/base.rb', line 9 def scopes_configuration self.class.scopes_configuration end |