Class: Embedson::Model::MethodBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/embedson/model/method_builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(klass, name, options) ⇒ MethodBuilder

Returns a new instance of MethodBuilder.



8
9
10
11
12
# File 'lib/embedson/model/method_builder.rb', line 8

def initialize(klass, name, options)
  @klass = klass
  @field_name = name
  @options = options
end

Instance Attribute Details

#field_nameObject (readonly)

Returns the value of attribute field_name.



6
7
8
# File 'lib/embedson/model/method_builder.rb', line 6

def field_name
  @field_name
end

#klassObject (readonly)

Returns the value of attribute klass.



6
7
8
# File 'lib/embedson/model/method_builder.rb', line 6

def klass
  @klass
end

#optionsObject (readonly)

Returns the value of attribute options.



6
7
8
# File 'lib/embedson/model/method_builder.rb', line 6

def options
  @options
end

Instance Method Details

#column_nameObject



24
25
26
# File 'lib/embedson/model/method_builder.rb', line 24

def column_name
  @column_name ||= options.fetch(:column_name, nil) || field_name
end

#embeddedObject



19
20
21
22
# File 'lib/embedson/model/method_builder.rb', line 19

def embedded
  EmbeddedBuilder.new(self).define
  generate_common
end

#embedsObject



14
15
16
17
# File 'lib/embedson/model/method_builder.rb', line 14

def embeds
  EmbedsBuilder.new(self).define
  generate_common
end

#instance_var_nameObject



32
33
34
# File 'lib/embedson/model/method_builder.rb', line 32

def instance_var_name
  @instance_var_name ||= "@#{field_name}"
end

#inverse_getObject



36
37
38
# File 'lib/embedson/model/method_builder.rb', line 36

def inverse_get
  @inverse_get ||= options.fetch(:inverse_of, nil) || klass.name.demodulize.tableize.singularize
end

#inverse_setObject



40
41
42
# File 'lib/embedson/model/method_builder.rb', line 40

def inverse_set
  @inverse_set ||= "#{inverse_get}="
end


28
29
30
# File 'lib/embedson/model/method_builder.rb', line 28

def related_klass_name
  @related_klass_name ||= (options.fetch(:class_name, nil) || field_name).to_s.classify
end