Sha256: dc6b30ac598f15c5a207865e84b7215f9add75d59c14c82560195421ae628289

Contents?: true

Size: 1.45 KB

Versions: 15

Compression:

Stored size: 1.45 KB

Contents

class CardController
  # methods for interpretation of card marks requested
  module Mark
    private

    def load_mark
      params[:mark] = interpret_mark params[:mark]
    end

    def interpret_mark mark
      case mark
      when "*previous"
        # Why support this? It's only needed in Success, right? Deprecate?
        hard_redirect Card::Env.previous_location
      when nil
        implicit_mark
      else
        explicit_mark mark
      end
    end

    def explicit_mark mark
      # we should find the place where we produce these bad urls
      # mark.valid_encoding? ? mark : mark.force_encoding("ISO-8859-1").encode("UTF-8")
      mark
    end

    def implicit_mark
      case
      when initial_setup
        ""
      when (name = mark_from_card_hash)
        name
      when view_does_not_require_name?
        ""
      else
        home_mark
      end
    end

    def home_mark
      Card::Rule.global_setting(:home) || "Home"
    end

    def view_does_not_require_name?
      return false unless (view = params[:view]&.to_sym)

      Card::Set::Format::AbstractFormat::ViewOpts.unknown_ok[view]
    end

    def mark_from_card_hash
      params.dig :card, :name
    end

    # alters params
    def initial_setup
      return unless Card::Auth.needs_setup? && Card::Env.html?

      prepare_setup_card!
    end

    def prepare_setup_card!
      params[:card] = { type_id: Card.default_accounted_type_id }
      params[:view] = "setup"
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
decko-0.18.1 lib/card_controller/mark.rb
decko-0.18.0 lib/card_controller/mark.rb
decko-0.17.0 lib/card_controller/mark.rb
decko-0.16.0 lib/card_controller/mark.rb
decko-0.15.6 lib/card_controller/mark.rb
decko-0.15.5 lib/card_controller/mark.rb
decko-0.15.4 lib/card_controller/mark.rb
decko-0.15.3 lib/card_controller/mark.rb
decko-0.15.2.pre1 lib/card_controller/mark.rb
decko-0.15.1.1 lib/card_controller/mark.rb
decko-0.15.1 lib/card_controller/mark.rb
decko-0.15.0 lib/card_controller/mark.rb
decko-0.14.2 lib/card_controller/mark.rb
decko-0.14.1 lib/card_controller/mark.rb
decko-0.14.0 lib/card_controller/mark.rb