Class: Vorpal::Dsl::DefaultsGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/vorpal/dsl/defaults_generator.rb

Instance Method Summary collapse

Constructor Details

#initialize(domain_class, db_driver) ⇒ DefaultsGenerator

Returns a new instance of DefaultsGenerator.



9
10
11
12
# File 'lib/vorpal/dsl/defaults_generator.rb', line 9

def initialize(domain_class, db_driver)
  @domain_class = domain_class
  @db_driver = db_driver
end

Instance Method Details

#associated_class(association_name) ⇒ Object



38
39
40
# File 'lib/vorpal/dsl/defaults_generator.rb', line 38

def associated_class(association_name)
  module_parent.const_get(ActiveSupport::Inflector.classify(association_name.to_s))
end

#build_db_class(user_table_name) ⇒ Object



14
15
16
# File 'lib/vorpal/dsl/defaults_generator.rb', line 14

def build_db_class(user_table_name)
  @db_driver.build_db_class(@domain_class, user_table_name || table_name)
end

#deserializer(attrs) ⇒ Object



28
29
30
31
32
# File 'lib/vorpal/dsl/defaults_generator.rb', line 28

def deserializer(attrs)
  Class.new(SimpleSerializer::Deserializer) do
    object_attributes *attrs
  end
end

#foreign_key(name) ⇒ Object



34
35
36
# File 'lib/vorpal/dsl/defaults_generator.rb', line 34

def foreign_key(name)
  ActiveSupport::Inflector.foreign_key(name.to_s)
end

#serializer(attrs) ⇒ Object



22
23
24
25
26
# File 'lib/vorpal/dsl/defaults_generator.rb', line 22

def serializer(attrs)
  Class.new(SimpleSerializer::Serializer) do
    hash_attributes *attrs
  end
end

#table_nameObject



18
19
20
# File 'lib/vorpal/dsl/defaults_generator.rb', line 18

def table_name
  ActiveSupport::Inflector.tableize(@domain_class.name)
end