Class: ActiverecordToPoro::Metadata
- Inherits:
-
Object
- Object
- ActiverecordToPoro::Metadata
- Defined in:
- lib/activerecord_to_poro/metadata.rb
Instance Attribute Summary collapse
-
#source_object_info ⇒ Object
Returns the value of attribute source_object_info.
Instance Method Summary collapse
- #create_source_info(ar_object) ⇒ Object
- #for_ar_class(ar_class_name) ⇒ Object
-
#initialize ⇒ Metadata
constructor
A new instance of Metadata.
- #initialize_from_ar(ar_object = nil) ⇒ Object
- #set_source_info(ar_object) ⇒ Object
- #to_hash ⇒ Object
Constructor Details
#initialize ⇒ Metadata
Returns a new instance of Metadata.
26 27 28 |
# File 'lib/activerecord_to_poro/metadata.rb', line 26 def initialize() self.source_object_info = Set.new() end |
Instance Attribute Details
#source_object_info ⇒ Object
Returns the value of attribute source_object_info.
24 25 26 |
# File 'lib/activerecord_to_poro/metadata.rb', line 24 def source_object_info @source_object_info end |
Instance Method Details
#create_source_info(ar_object) ⇒ Object
48 49 50 51 52 53 54 55 |
# File 'lib/activerecord_to_poro/metadata.rb', line 48 def create_source_info(ar_object) SourceObjectInfo.new(class_name: ar_object.class.name, column: ar_object.class.primary_key, value: ar_object.send(ar_object.class.primary_key), object_id: ar_object.object_id, lock_version: ar_object.respond_to?(:lock_version) ? ar_object.lock_version : nil ) end |
#for_ar_class(ar_class_name) ⇒ Object
36 37 38 39 40 |
# File 'lib/activerecord_to_poro/metadata.rb', line 36 def for_ar_class(ar_class_name) source_object_info.find(->{SourceObjectInfo.new}){|data| data.class_name == ar_class_name } end |
#initialize_from_ar(ar_object = nil) ⇒ Object
30 31 32 33 34 |
# File 'lib/activerecord_to_poro/metadata.rb', line 30 def initialize_from_ar(ar_object=nil) unless ar_object.nil? set_source_info(ar_object) end end |
#set_source_info(ar_object) ⇒ Object
42 43 44 45 46 |
# File 'lib/activerecord_to_poro/metadata.rb', line 42 def set_source_info(ar_object) new_info = create_source_info(ar_object) self.source_object_info.delete_if { |info| info == new_info } self.source_object_info << new_info end |
#to_hash ⇒ Object
57 58 59 |
# File 'lib/activerecord_to_poro/metadata.rb', line 57 def to_hash { source_objects_info: source_object_info.map(&:to_hash) } end |