Sha256: d71586bd5a9245c9505714c784dcbbf6049f98cb66fafe045728751be9d08141
Contents?: true
Size: 1.81 KB
Versions: 15
Compression:
Stored size: 1.81 KB
Contents
# frozen_string_literal: true module Quby module Compiler module Entities class Flag < Struct.new(:key, :description_true, :description_false, :description, :internal, :trigger_on, :shows_questions, :hides_questions, :depends_on, :default_in_interface) # rubocop:disable ParameterLists def initialize(key:, description_true: nil, description_false: nil, description: nil, internal: false, trigger_on: true, shows_questions: [], hides_questions: [], depends_on: [], # used in interface to hide this flag unless the depended on flag is set to true default_in_interface: nil) # used in interface to set a default for the flag state, # does not have an effect outside of the interface super(key, description_true, description_false, description, internal, trigger_on, shows_questions, hides_questions, Array.wrap(depends_on).map(&:to_s), default_in_interface) ensure_valid_descriptions end # rubocop:enable ParameterLists def if_triggered_by(answer_flags) yield if answer_flags[key] == trigger_on end def variable_description "#{description} (true - '#{description_true}', false - '#{description_false}')" end private def ensure_valid_descriptions unless (description_false.present? && description_true.present?) || description.present? raise "Flag '#{key}' Requires at least either both description_true and description_false or a description" end end end end end end
Version data entries
15 entries across 15 versions & 1 rubygems