Sha256: 1b1ca05755309551b465a8abc5d3401d482ff04f43e7fe9432fda8970cf27e3a
Contents?: true
Size: 953 Bytes
Versions: 7
Compression:
Stored size: 953 Bytes
Contents
# frozen_string_literal: true module InferredCrumpets class ActionProcessor NEW_ACTIONS = %w[new create].freeze private_constant :NEW_ACTIONS EDIT_ACTIONS = %w[edit update].freeze private_constant :EDIT_ACTIONS IGNORED_ACTIONS = %w[show].freeze private_constant :IGNORED_ACTIONS NEW_LABEL = 'New' private_constant :NEW_LABEL EDIT_LABEL = 'Edit' private_constant :EDIT_LABEL def self.for_action(action) new(action).call end def initialize(action) @action = action end def call return build_opts(nil) if IGNORED_ACTIONS.include?(@action) return build_opts(NEW_LABEL, false) if NEW_ACTIONS.include?(@action) return build_opts(EDIT_LABEL) if EDIT_ACTIONS.include?(@action) build_opts(@action.humanize) end private def build_opts(label, has_subject = true) OpenStruct.new(label: label, has_subject?: has_subject) end end end
Version data entries
7 entries across 7 versions & 1 rubygems