Module: ActiveModule::Enum::ClassMethodsDefiner
- Included in:
- ActiveModule::Enum
- Defined in:
- lib/active_module/enum/class_methods_definer.rb
Instance Method Summary collapse
- #build_fields_map(modules, mapping) ⇒ Object
- #define_class_query(attribute_name, mod, value_name, opts, existing) ⇒ Object
- #define_enum_scope(attribute_name, mod, value_name, opts, existing) ⇒ Object
- #define_fields_method(attribute_name, modules, mapping) ⇒ Object
Instance Method Details
#build_fields_map(modules, mapping) ⇒ Object
42 43 44 45 46 |
# File 'lib/active_module/enum/class_methods_definer.rb', line 42 def build_fields_map(modules, mapping) modules.each_with_object({}) do |mod, h| h[mod] = mapping[mod] || mod.name end end |
#define_class_query(attribute_name, mod, value_name, opts, existing) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/active_module/enum/class_methods_definer.rb', line 6 def define_class_query(attribute_name, mod, value_name, opts, existing) name = enum_method_name(value_name, opts) return if existing[:singleton] .include?(name.to_sym) return if respond_to?(name) define_singleton_method(name) do where(attribute_name => mod) end end |
#define_enum_scope(attribute_name, mod, value_name, opts, existing) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/active_module/enum/class_methods_definer.rb', line 19 def define_enum_scope(attribute_name, mod, value_name, opts, existing) name = enum_method_name(value_name, opts) scope_name = :"with_#{name}" return if existing[:singleton] .include?(scope_name) return if respond_to?(scope_name) define_singleton_method(scope_name) do where(attribute_name => mod) end end |
#define_fields_method(attribute_name, modules, mapping) ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/active_module/enum/class_methods_definer.rb', line 33 def define_fields_method(attribute_name, modules, mapping) fields = build_fields_map(modules, mapping) name = attribute_name.to_s.pluralize return if singleton_methods.include?(name.to_sym) return if respond_to?(name) define_singleton_method(name) { fields } end |