Module: CommandPost::AutoLoad
- Included in:
- Persistence
- Defined in:
- lib/command_post/persistence/auto_load.rb
Instance Method Summary collapse
- #auto_load_fields ⇒ Object
- #local_peristent_fields ⇒ Object
- #populate_auto_load_fields ⇒ Object
- #populate_local_persistent_objects ⇒ Object
- #to_pretty_pp ⇒ Object
Instance Method Details
#auto_load_fields ⇒ Object
6 7 8 9 |
# File 'lib/command_post/persistence/auto_load.rb', line 6 def auto_load_fields schema_fields.select {|key, value| value[:auto_load] == true }.keys end |
#local_peristent_fields ⇒ Object
12 13 14 15 |
# File 'lib/command_post/persistence/auto_load.rb', line 12 def local_peristent_fields schema_fields.select {|key, value| value[:location] == :local && value[:type].superclass == Persistence }.keys end |
#populate_auto_load_fields ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/command_post/persistence/auto_load.rb', line 18 def populate_auto_load_fields auto_load_fields.select {|x| @data.keys.include? x}.each do |field| if @data[field].class == Array if schema_fields[field][:location] == :remote array_of_objects = Array.new array_of_pointers = @data[field] array_of_pointers.each do |pointer| if pointer.respond_to? :aggregate_pointer pointer = pointer.aggregate_pointer end obj = Aggregate.get_by_aggregate_id(Object.const_get(pointer[:aggregate_type]), pointer[:aggregate_id]) array_of_objects << obj end array_of_pointers.clear @data[field].clear @data[field] += array_of_objects end else @data[field] = Aggregate.get_by_aggregate_id( schema_fields[field][:type], @data[field][:aggregate_id]) end end end |
#populate_local_persistent_objects ⇒ Object
60 61 62 63 64 65 66 |
# File 'lib/command_post/persistence/auto_load.rb', line 60 def populate_local_persistent_objects local_peristent_fields.each do |field| klass = schema_fields[field][:type] @data[field] = klass.load_from_hash klass, HashUtil.symbolize_keys(@data[field]) @data[field].populate_local_persitent_objects end end |
#to_pretty_pp ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/command_post/persistence/auto_load.rb', line 42 def to_pretty_pp len = 0 result = '' @data.keys.map{|key| len = key.length if (key.length > len) } @data.keys.reject{|key| /aggregate/.match key}.each do |key| label = "%#{len}s :" % key if auto_load_fields.include? key result += "\n#{label} (remote object)" result += (@data[key]).to_s else result += "#{label} #{@data[key]}" end end result end |