Sha256: fc3ff8fe7bdc0631a991f0eb3dd2f4b0d44c69a36de584d9cd6a6470b7ed9cf3

Contents?: true

Size: 577 Bytes

Versions: 1

Compression:

Stored size: 577 Bytes

Contents

module CurlyMustache
  module Attributes
    class Definition
      attr_reader :name, :type
      
      def initialize(name, type, options = {})
        @options = options.symbolize_keys.reverse_merge :default => nil,
                                                        :allow_nil => true
        @name = name.to_sym
        @type = type.to_sym
        @caster = Types[type].caster
      end
      
      def cast(value)
        if value.nil? and @options[:allow_nil]
          nil
        else
          @caster.call(value)
        end
      end
      
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
curly_mustache-0.1.0 lib/curly_mustache/attributes/definition.rb