Class: FlexibleEnum::ScopeConfigurator

Inherits:
AbstractConfigurator show all
Defined in:
lib/flexible_enum/scope_configurator.rb

Instance Attribute Summary

Attributes inherited from AbstractConfigurator

#attribute_name, #elements, #feature_module, #module_for_elements

Instance Method Summary collapse

Methods inherited from AbstractConfigurator

#add_class_method, #add_instance_method

Instance Method Details

#applyObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/flexible_enum/scope_configurator.rb', line 3

def apply
  configurator = self

  elements.each do |element_name, element_config|
    add_class_method(scope_name(element_name)) do
      where(configurator.attribute_name => element_config[:value])
    end

    if element_config[:inverse]
      add_class_method(scope_name(element_config[:inverse])) do
        where.not(configurator.attribute_name => element_config[:value])
      end
    end
  end
end