Class: SpreeCmCommissioner::PlaceService
- Inherits:
-
Object
- Object
- SpreeCmCommissioner::PlaceService
- Defined in:
- app/interactors/spree_cm_commissioner/place_service.rb
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(model:, place_class:, params:) ⇒ PlaceService
constructor
A new instance of PlaceService.
Constructor Details
#initialize(model:, place_class:, params:) ⇒ PlaceService
Returns a new instance of PlaceService.
3 4 5 6 7 |
# File 'app/interactors/spree_cm_commissioner/place_service.rb', line 3 def initialize(model:, place_class:, params:) @model = model # e.g., Taxon or Product @place_class = place_class # e.g., TaxonPlace or ProductPlace @params = params end |
Instance Method Details
#call ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'app/interactors/spree_cm_commissioner/place_service.rb', line 9 def call @base64_content = @params[:base_64_content] @place_name = @params[:place_name] if @base64_content.blank? existing_place = @place_class existing_place.delete if existing_place && @place_name.blank? return end place = PlaceDecoder.process_place(@base64_content) return if place.nil? if place.save # rubocop:disable Style/GuardClause existing_place = @place_class if existing_place.present? existing_place.update(place_id: place.id) else @model.places << place end end end |