Module: NumeritajTipo::Neo4j

Includes:
Base
Defined in:
lib/numeritaj_tipo/neo4j.rb,
lib/numeritaj_tipo/neo4j/type_converters/enum_converter.rb,
lib/numeritaj_tipo/neo4j/type_converters/symbol_converter.rb

Defined Under Namespace

Modules: TypeConverters

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Base

#enumerize

Class Method Details

.included(base) ⇒ Object



9
10
11
# File 'lib/numeritaj_tipo/neo4j.rb', line 9

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

Instance Method Details

#define_enum(attribute_name, type, default_value) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/numeritaj_tipo/neo4j.rb', line 13

def define_enum(attribute_name, type, default_value)
  property_options = {type: type, default: type < NumeritajTipo::EnumBase ? type.build(default_value) : default_value}
  property_options.merge!(typecaster: NumeritajTipo::Neo4j::TypeConverters::SymbolConverter) if type == Symbol
  property_options.merge!(typecaster: NumeritajTipo::Neo4j::TypeConverters::EnumConverter.converter_for(type)) if type < NumeritajTipo::EnumBase

  property attribute_name, property_options
end

#define_scopes(attribute_definition) ⇒ Object



21
22
23
24
25
# File 'lib/numeritaj_tipo/neo4j.rb', line 21

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