Class: ExtractAssociatedObject
- Inherits:
-
Object
- Object
- ExtractAssociatedObject
- Defined in:
- lib/extract_associated_object.rb
Instance Attribute Summary collapse
-
#associated_object ⇒ Object
readonly
Returns the value of attribute associated_object.
-
#object ⇒ Object
readonly
Returns the value of attribute object.
-
#schema_tables ⇒ Object
readonly
Returns the value of attribute schema_tables.
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(object, associated_object = []) ⇒ ExtractAssociatedObject
constructor
A new instance of ExtractAssociatedObject.
Constructor Details
#initialize(object, associated_object = []) ⇒ ExtractAssociatedObject
Returns a new instance of ExtractAssociatedObject.
8 9 10 11 12 |
# File 'lib/extract_associated_object.rb', line 8 def initialize(object, associated_object = []) @object = object[0] @associated_object = associated_object @schema_tables = ActiveRecord::Base.connection.tables end |
Instance Attribute Details
#associated_object ⇒ Object (readonly)
Returns the value of attribute associated_object.
6 7 8 |
# File 'lib/extract_associated_object.rb', line 6 def associated_object @associated_object end |
#object ⇒ Object (readonly)
Returns the value of attribute object.
6 7 8 |
# File 'lib/extract_associated_object.rb', line 6 def object @object end |
#schema_tables ⇒ Object (readonly)
Returns the value of attribute schema_tables.
6 7 8 |
# File 'lib/extract_associated_object.rb', line 6 def schema_tables @schema_tables end |
Instance Method Details
#call ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/extract_associated_object.rb', line 14 def call associated_tables_names.each do |table, column| value = object[column] next if value.nil? result = ActiveRecord::Base.connection.execute("SELECT * FROM #{table} WHERE id='#{value}'").to_a result[0].delete('updated_at') result[0].delete('created_at') associated_object << { table: table, attributes: result } ExtractAssociatedObject.new(result, associated_object).call end CreateFactory.call(associated_object) end |