Sha256: 737fd20720ce77eeee0711e1ef228397efbb8f0de2b2d4846abf706fe0729127

Contents?: true

Size: 922 Bytes

Versions: 4

Compression:

Stored size: 922 Bytes

Contents

class Card
  class Path
    cattr_accessor :cast_params
    self.cast_params = { slot: { hide: :array, show: :array, wrap: :array } }.freeze

    # normalizes certain path opts to specified data types
    module CastParams
      private

      def cast_path_hash hash, cast_hash=nil
        return hash unless hash.is_a? Hash
        cast_each_path_hash hash, (cast_hash || self.class.cast_params)
        hash
      end

      def cast_each_path_hash hash, cast_hash
        hash.each do |key, value|
          next unless (cast_to = cast_hash[key])
          hash[key] = cast_path_value value, cast_to
        end
      end

      def cast_path_value value, cast_to
        if cast_to.is_a? Hash
          cast_path_hash value, cast_to
        else
          send "cast_path_value_as_#{cast_to}", value
        end
      end

      def cast_path_value_as_array value
        Array.wrap value
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
card-mod-format-0.11.4 lib/card/path/cast_params.rb
card-mod-format-0.11.3 lib/card/path/cast_params.rb
card-mod-format-0.11.2 lib/card/path/cast_params.rb
card-mod-format-0.11.1 lib/card/path/cast_params.rb