Class: Ecm::Cms::ImportPartialsService
- Inherits:
-
Itsf::Services::V2::Service::Base
- Object
- Itsf::Services::V2::Service::Base
- Ecm::Cms::ImportPartialsService
- Defined in:
- app/services/ecm/cms/import_partials_service.rb
Defined Under Namespace
Classes: PartialInFileSystem
Instance Attribute Summary collapse
-
#force ⇒ Object
Returns the value of attribute force.
-
#view_path ⇒ Object
Returns the value of attribute view_path.
Instance Method Summary collapse
- #do_work ⇒ Object
-
#initialize(attributes = {}) ⇒ ImportPartialsService
constructor
A new instance of ImportPartialsService.
Constructor Details
#initialize(attributes = {}) ⇒ ImportPartialsService
Returns a new instance of ImportPartialsService.
68 69 70 71 |
# File 'app/services/ecm/cms/import_partials_service.rb', line 68 def initialize(attributes = {}) attributes.reverse_merge!(view_path: Rails.root.join(*%w(app views)), force: false) super(attributes) end |
Instance Attribute Details
#force ⇒ Object
Returns the value of attribute force.
64 65 66 |
# File 'app/services/ecm/cms/import_partials_service.rb', line 64 def force @force end |
#view_path ⇒ Object
Returns the value of attribute view_path.
64 65 66 |
# File 'app/services/ecm/cms/import_partials_service.rb', line 64 def view_path @view_path end |
Instance Method Details
#do_work ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'app/services/ecm/cms/import_partials_service.rb', line 73 def do_work info "Environment: #{Rails.env}" respond unless valid? @partials = load_partials partials_count = @partials.size info "Processing #{partials_count} partials in #{view_path}:" @partials.each_with_index do |partial, index| info " (#{index + 1}/#{partials_count}) #{partial.human}" attributes_hash = partial.to_partial_attributes_hash partial = force ? find_or_initialize_partial(attributes_hash) : initialize_partial(attributes_hash) new_record = partial.new_record? partial.attributes = attributes_hash if partial.save info " #{new_record ? 'Created' : 'Updated'} #{partial.human}" else info " Could not #{new_record ? 'create' : 'update'} #{partial.human}. Errors: #{partial.errors..to_sentence}" end end respond end |