Sha256: f0ae3b5966bd17ccb3832ceb2ef994022608f6156befd172fb6bd62fee3672f1

Contents?: true

Size: 660 Bytes

Versions: 12

Compression:

Stored size: 660 Bytes

Contents

module Kafo
  module Params
    class Hash < Param
      def value=(value)
        super
        @value = typecast(@value)
      end

      def multivalued?
        true
      end

      def condition_value
        value.inspect
      end

      private

      def typecast(value)
        if value.nil?
          nil
        elsif value.is_a?(::Hash)
          value
        else
          value = [value].flatten
          ::Hash[value.map { |v| v.split(':', 2) }]
        end
      rescue NoMethodError => e
        KafoConfigure.logger.warn "Could not typecast #{value} for parameter #{name}, defaulting to {}"
        return {}
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
kafo-0.6.5 lib/kafo/params/hash.rb
kafo-0.6.4 lib/kafo/params/hash.rb
kafo-0.6.3 lib/kafo/params/hash.rb
kafo-0.6.2 lib/kafo/params/hash.rb
kafo-0.6.1 lib/kafo/params/hash.rb
kafo-0.6.0 lib/kafo/params/hash.rb
kafo-0.5.5 lib/kafo/params/hash.rb
kafo-0.5.4 lib/kafo/params/hash.rb
kafo-0.5.3 lib/kafo/params/hash.rb
kafo-0.5.2 lib/kafo/params/hash.rb
kafo-0.5.1 lib/kafo/params/hash.rb
kafo-0.5.0 lib/kafo/params/hash.rb