class ToFactory::FileSync
Public Class Methods
new(m = ToFactory::Finders::Model.new, fw = ToFactory::FileWriter.new, ff = ToFactory::Finders::Factory.new)
click to toggle source
# File lib/to_factory/file_sync.rb, line 3 def initialize(m = ToFactory::Finders::Model.new, fw = ToFactory::FileWriter.new, ff = ToFactory::Finders::Factory.new) @model_finder = wrap_model(m) @file_writer = fw @factory_finder = ff end
Public Instance Methods
all_representations(exclusions=[])
click to toggle source
# File lib/to_factory/file_sync.rb, line 15 def all_representations(exclusions=[]) Collation.organize( new_representations(exclusions), existing_representations) end
new_representations(exclusions=[])
click to toggle source
# File lib/to_factory/file_sync.rb, line 21 def new_representations(exclusions=[]) instances = @model_finder.call(exclusions: exclusions) instances.map{|r| Representation.from(r) } end
perform(exclusions=[])
click to toggle source
# File lib/to_factory/file_sync.rb, line 11 def perform(exclusions=[]) @file_writer.write(all_representations exclusions) end
Private Instance Methods
existing_representations()
click to toggle source
# File lib/to_factory/file_sync.rb, line 29 def existing_representations @factory_finder.call end
wrap_model(m)
click to toggle source
# File lib/to_factory/file_sync.rb, line 33 def wrap_model(m) if m.respond_to?(:call) m else lambda{|exclusions| exclusions ||= [] records = if m.is_a?(ActiveRecord::Base) Array m else m end records.reject{|o,_| exclusions.include?(o.class)} } end end