Class: SpreeCmCommissioner::SpriteImportService
- Inherits:
-
Object
- Object
- SpreeCmCommissioner::SpriteImportService
- Includes:
- Spree::ServiceModule::Base
- Defined in:
- app/services/spree_cm_commissioner/sprite_import_service.rb
Instance Attribute Summary collapse
-
#menu ⇒ Object
readonly
Returns the value of attribute menu.
-
#positions_params ⇒ Object
readonly
Returns the value of attribute positions_params.
-
#sprite_file ⇒ Object
readonly
Returns the value of attribute sprite_file.
-
#sprite_settings ⇒ Object
readonly
Returns the value of attribute sprite_settings.
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(menu:, sprite_file: nil, sprite_settings: {}, positions_params: {}) ⇒ SpriteImportService
constructor
A new instance of SpriteImportService.
- #sprite_gap ⇒ Object
- #sprite_icon_size ⇒ Object
- #sprite_padding ⇒ Object
- #update ⇒ Object
Constructor Details
#initialize(menu:, sprite_file: nil, sprite_settings: {}, positions_params: {}) ⇒ SpriteImportService
Returns a new instance of SpriteImportService.
7 8 9 10 11 12 |
# File 'app/services/spree_cm_commissioner/sprite_import_service.rb', line 7 def initialize(menu:, sprite_file: nil, sprite_settings: {}, positions_params: {}) @menu = @sprite_file = sprite_file @sprite_settings = (sprite_settings || {}).with_indifferent_access @positions_params = positions_params || {} end |
Instance Attribute Details
#menu ⇒ Object (readonly)
Returns the value of attribute menu.
5 6 7 |
# File 'app/services/spree_cm_commissioner/sprite_import_service.rb', line 5 def @menu end |
#positions_params ⇒ Object (readonly)
Returns the value of attribute positions_params.
5 6 7 |
# File 'app/services/spree_cm_commissioner/sprite_import_service.rb', line 5 def positions_params @positions_params end |
#sprite_file ⇒ Object (readonly)
Returns the value of attribute sprite_file.
5 6 7 |
# File 'app/services/spree_cm_commissioner/sprite_import_service.rb', line 5 def sprite_file @sprite_file end |
#sprite_settings ⇒ Object (readonly)
Returns the value of attribute sprite_settings.
5 6 7 |
# File 'app/services/spree_cm_commissioner/sprite_import_service.rb', line 5 def sprite_settings @sprite_settings end |
Instance Method Details
#call ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'app/services/spree_cm_commissioner/sprite_import_service.rb', line 26 def call validate_sprite_file! ActiveRecord::Base.transaction do build_and_save_positions attach_sprite_file end success(message: 'Sprite and positions imported successfully!') rescue StandardError => e failure(e.) end |
#sprite_gap ⇒ Object
18 19 20 |
# File 'app/services/spree_cm_commissioner/sprite_import_service.rb', line 18 def sprite_gap sprite_settings[:gap] end |
#sprite_icon_size ⇒ Object
22 23 24 |
# File 'app/services/spree_cm_commissioner/sprite_import_service.rb', line 22 def sprite_icon_size sprite_settings[:icon_size].to_i.positive? ? sprite_settings[:icon_size].to_i : 64 end |
#sprite_padding ⇒ Object
14 15 16 |
# File 'app/services/spree_cm_commissioner/sprite_import_service.rb', line 14 def sprite_padding sprite_settings[:padding] end |
#update ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 |
# File 'app/services/spree_cm_commissioner/sprite_import_service.rb', line 39 def update ActiveRecord::Base.transaction do build_and_save_positions attach_sprite_file if sprite_file.present? end = sprite_file.present? ? 'Sprite and positions updated successfully!' : 'Positions updated successfully!' success(message: ) rescue StandardError => e failure(e.) end |