Sha256: 46c10474de02c312366e2f4aa42322a4903a45981657422b86368ff5b1de1f28

Contents?: true

Size: 924 Bytes

Versions: 24

Compression:

Stored size: 924 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

24 entries across 24 versions & 1 rubygems

Version Path
card-mod-format-0.18.1 lib/card/path/cast_params.rb
card-mod-format-0.18.0 lib/card/path/cast_params.rb
card-mod-format-0.17.0 lib/card/path/cast_params.rb
card-mod-format-0.16.0 lib/card/path/cast_params.rb
card-mod-format-0.15.6 lib/card/path/cast_params.rb
card-mod-format-0.15.5 lib/card/path/cast_params.rb
card-mod-format-0.15.4 lib/card/path/cast_params.rb
card-mod-format-0.15.3 lib/card/path/cast_params.rb
card-mod-format-0.15.2.pre1 lib/card/path/cast_params.rb
card-mod-format-0.15.1.1 lib/card/path/cast_params.rb
card-mod-format-0.15.1 lib/card/path/cast_params.rb
card-mod-format-0.15.0 lib/card/path/cast_params.rb
card-mod-format-0.14.2 lib/card/path/cast_params.rb
card-mod-format-0.14.1 lib/card/path/cast_params.rb
card-mod-format-0.14.0 lib/card/path/cast_params.rb
card-mod-format-0.13.4 lib/card/path/cast_params.rb
card-mod-format-0.13.3 lib/card/path/cast_params.rb
card-mod-format-0.13.2 lib/card/path/cast_params.rb
card-mod-format-0.13.1 lib/card/path/cast_params.rb
card-mod-format-0.13.0 lib/card/path/cast_params.rb