Class: Embedson::Model::MethodBuilder
- Inherits:
-
Object
- Object
- Embedson::Model::MethodBuilder
- Defined in:
- lib/embedson/model/method_builder.rb
Instance Attribute Summary collapse
-
#field_name ⇒ Object
readonly
Returns the value of attribute field_name.
-
#klass ⇒ Object
readonly
Returns the value of attribute klass.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #column_name ⇒ Object
- #embedded ⇒ Object
- #embeds ⇒ Object
- #hash_method ⇒ Object
-
#initialize(klass, name, options) ⇒ MethodBuilder
constructor
A new instance of MethodBuilder.
- #instance_var_name ⇒ Object
- #inverse_get ⇒ Object
- #inverse_set ⇒ Object
- #related_klass_name ⇒ Object
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, ) @klass = klass @field_name = name @options = end |
Instance Attribute Details
#field_name ⇒ Object (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 |
#klass ⇒ Object (readonly)
Returns the value of attribute klass.
6 7 8 |
# File 'lib/embedson/model/method_builder.rb', line 6 def klass @klass end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
6 7 8 |
# File 'lib/embedson/model/method_builder.rb', line 6 def @options end |
Instance Method Details
#column_name ⇒ Object
28 29 30 |
# File 'lib/embedson/model/method_builder.rb', line 28 def column_name @column_name ||= .fetch(:column_name, nil) || field_name end |
#embedded ⇒ Object
19 20 21 22 |
# File 'lib/embedson/model/method_builder.rb', line 19 def EmbeddedBuilder.new(self).define generate_common end |
#embeds ⇒ Object
14 15 16 17 |
# File 'lib/embedson/model/method_builder.rb', line 14 def EmbedsBuilder.new(self).define generate_common end |
#hash_method ⇒ Object
24 25 26 |
# File 'lib/embedson/model/method_builder.rb', line 24 def hash_method @hash_method ||= .fetch(:hash_method, nil) || :to_h end |
#instance_var_name ⇒ Object
36 37 38 |
# File 'lib/embedson/model/method_builder.rb', line 36 def instance_var_name @instance_var_name ||= "@#{field_name}" end |
#inverse_get ⇒ Object
40 41 42 |
# File 'lib/embedson/model/method_builder.rb', line 40 def inverse_get @inverse_get ||= .fetch(:inverse_of, nil) || klass.name.demodulize.tableize.singularize end |
#inverse_set ⇒ Object
44 45 46 |
# File 'lib/embedson/model/method_builder.rb', line 44 def inverse_set @inverse_set ||= "#{inverse_get}=" end |
#related_klass_name ⇒ Object
32 33 34 |
# File 'lib/embedson/model/method_builder.rb', line 32 def @related_klass_name ||= (.fetch(:class_name, nil) || field_name).to_s.camelize end |