Class: Vorpal::Dsl::ConfigBuilder

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

Instance Method Summary collapse

Constructor Details

#initialize(clazz, options, db_driver) ⇒ ConfigBuilder

Returns a new instance of ConfigBuilder.



12
13
14
15
16
17
18
19
20
# File 'lib/vorpal/dsl/config_builder.rb', line 12

def initialize(clazz, options, db_driver)
  @domain_class = clazz
  @class_options = options
  @has_manys = []
  @has_ones = []
  @belongs_tos = []
  @attributes = []
  @defaults_generator = DefaultsGenerator.new(clazz, db_driver)
end

Instance Method Details

#attributes(*attributes) ⇒ Object



23
24
25
# File 'lib/vorpal/dsl/config_builder.rb', line 23

def attributes(*attributes)
  @attributes.concat(attributes)
end

#attributes_with_idObject



53
54
55
# File 'lib/vorpal/dsl/config_builder.rb', line 53

def attributes_with_id
  [:id].concat @attributes
end

#belongs_to(name, options = {}) ⇒ Object



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

def belongs_to(name, options={})
  @belongs_tos << build_belongs_to({name: name}.merge(options))
end

#buildObject



43
44
45
46
47
48
49
50
# File 'lib/vorpal/dsl/config_builder.rb', line 43

def build
  class_config = build_class_config
  class_config.has_manys = @has_manys
  class_config.has_ones = @has_ones
  class_config.belongs_tos = @belongs_tos

  class_config
end

#has_many(name, options = {}) ⇒ Object



28
29
30
# File 'lib/vorpal/dsl/config_builder.rb', line 28

def has_many(name, options={})
  @has_manys << build_has_many({name: name}.merge(options))
end

#has_one(name, options = {}) ⇒ Object



33
34
35
# File 'lib/vorpal/dsl/config_builder.rb', line 33

def has_one(name, options={})
  @has_ones << build_has_one({name: name}.merge(options))
end