Class: Wizard::StepUpdater
- Inherits:
-
Object
- Object
- Wizard::StepUpdater
- Includes:
- ActiveModel::Model
- Defined in:
- lib/wizard/step_updater.rb
Instance Attribute Summary collapse
-
#fields ⇒ Object
Returns the value of attribute fields.
-
#refresh_required ⇒ Object
Returns the value of attribute refresh_required.
Instance Method Summary collapse
- #apply_setting(id) ⇒ Object
- #apply_settings(*ids) ⇒ Object
- #ensure_changed(id) ⇒ Object
-
#initialize(current_user, step, fields) ⇒ StepUpdater
constructor
A new instance of StepUpdater.
- #refresh_required? ⇒ Boolean
- #success? ⇒ Boolean
- #update ⇒ Object
- #update_setting(id, value) ⇒ Object
Constructor Details
#initialize(current_user, step, fields) ⇒ StepUpdater
Returns a new instance of StepUpdater.
9 10 11 12 13 14 |
# File 'lib/wizard/step_updater.rb', line 9 def initialize(current_user, step, fields) @current_user = current_user @step = step @refresh_required = false @fields = fields end |
Instance Attribute Details
#fields ⇒ Object
Returns the value of attribute fields.
7 8 9 |
# File 'lib/wizard/step_updater.rb', line 7 def fields @fields end |
#refresh_required ⇒ Object
Returns the value of attribute refresh_required.
7 8 9 |
# File 'lib/wizard/step_updater.rb', line 7 def refresh_required @refresh_required end |
Instance Method Details
#apply_setting(id) ⇒ Object
43 44 45 46 47 |
# File 'lib/wizard/step_updater.rb', line 43 def apply_setting(id) update_setting(id, @fields[id]) rescue Discourse::InvalidParameters => e errors.add(id, e.) end |
#apply_settings(*ids) ⇒ Object
53 54 55 |
# File 'lib/wizard/step_updater.rb', line 53 def apply_settings(*ids) ids.each { |id| apply_setting(id) } end |
#ensure_changed(id) ⇒ Object
49 50 51 |
# File 'lib/wizard/step_updater.rb', line 49 def ensure_changed(id) errors.add(id, "") if @fields[id] == SiteSetting.defaults[id] end |
#refresh_required? ⇒ Boolean
29 30 31 |
# File 'lib/wizard/step_updater.rb', line 29 def refresh_required? @refresh_required end |
#success? ⇒ Boolean
25 26 27 |
# File 'lib/wizard/step_updater.rb', line 25 def success? @errors.blank? end |
#update ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/wizard/step_updater.rb', line 16 def update @step.updater.call(self) if @step.present? && @step.updater.present? if success? logger = StaffActionLogger.new(@current_user) logger.log_wizard_step(@step) end end |
#update_setting(id, value) ⇒ Object
33 34 35 36 37 38 39 40 41 |
# File 'lib/wizard/step_updater.rb', line 33 def update_setting(id, value) value = value.strip if value.is_a?(String) if !value.is_a?(Upload) && SiteSetting.type_supervisor.get_type(id) == :upload value = Upload.get_from_url(value) || "" end SiteSetting.set_and_log(id, value, @current_user) if SiteSetting.get(id) != value end |