Module: NumeritajTipo::Mongoid

Includes:
Base
Defined in:
lib/numeritaj_tipo/mongoid.rb

Defined Under Namespace

Modules: Mongoize

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Base

#enumerize

Class Method Details

.included(base) ⇒ Object



7
8
9
# File 'lib/numeritaj_tipo/mongoid.rb', line 7

def self.included(base)
  base.extend self
end

Instance Method Details

#define_enum(attribute_name, type, default_value) ⇒ Object



11
12
13
14
15
# File 'lib/numeritaj_tipo/mongoid.rb', line 11

def define_enum(attribute_name, type, default_value)
  type_class = type.to_s.classify.constantize
  type_class = type_class.extend(Mongoize) if type_class < NumeritajTipo::EnumBase
  field attribute_name, type: type_class, default: type < NumeritajTipo::EnumBase ? type.build(default_value) : default_value
end

#define_scopes(attribute_definition) ⇒ Object



17
18
19
20
21
# File 'lib/numeritaj_tipo/mongoid.rb', line 17

def define_scopes(attribute_definition)
  attribute_definition.enum_values.each do |value|
    scope value, -> { where(attribute_definition.name => value) }
  end
end