Module: Pageflow::OutputSource
- Extended by:
- ActiveSupport::Concern
- Defined in:
- app/models/concerns/pageflow/output_source.rb
Constant Summary collapse
- STATE_MAPPING =
{ true => 'finished', false => 'skipped' }.freeze
Instance Method Summary collapse
- #externally_generated_outputs ⇒ Object
- #output_presences ⇒ Object
- #output_presences=(presences) ⇒ Object
- #output_present?(type) ⇒ Boolean
- #present_outputs ⇒ Object
Instance Method Details
#externally_generated_outputs ⇒ Object
47 48 49 |
# File 'app/models/concerns/pageflow/output_source.rb', line 47 def externally_generated_outputs [] end |
#output_presences ⇒ Object
42 43 44 45 |
# File 'app/models/concerns/pageflow/output_source.rb', line 42 def output_presences output_presences = self[:output_presences] || {} output_presences.merge(externally_generated_output_presences) end |
#output_presences=(presences) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'app/models/concerns/pageflow/output_source.rb', line 26 def output_presences=(presences) boolean_presences = presences.stringify_keys.each_with_object({}) do |(key, value), result| if value == true || value == STATE_MAPPING[true] result[key] = true elsif value == false || value == STATE_MAPPING[false] result[key] = false elsif value.blank? result[key] = nil end end self[:output_presences] = output_presences .merge(boolean_presences) .reject { |_key, value| value.nil? } end |
#output_present?(type) ⇒ Boolean
22 23 24 |
# File 'app/models/concerns/pageflow/output_source.rb', line 22 def output_present?(type) output_presences[type.to_s] end |
#present_outputs ⇒ Object
14 15 16 17 18 19 20 |
# File 'app/models/concerns/pageflow/output_source.rb', line 14 def present_outputs present_outputs_label_state_array = output_presences.select do |output_label, _output_state| output_present?(output_label) == true end present_outputs_label_state_array.map { |output_label_state| output_label_state[0].to_sym } end |