Sha256: 79c9aab987d04f4412104edecd23f01d09d1ca3714337c3d67039785cd7cc645
Contents?: true
Size: 1.32 KB
Versions: 13
Compression:
Stored size: 1.32 KB
Contents
module Pump class Dsl def initialize(&blk) raise ArgumentError unless block_given? instance_eval(&blk) end def config @config ||= [] end private def tag(name, options={}, &blk) method = if block_given? self.class.new(&blk).config else options.delete(:from) || (name.to_s =~ /-/ ? name.to_s.gsub('-', '_').to_sym : name) end config << ({ name => method }).merge(options) end alias_method :string, :tag def integer(name, options={}) with_type('integer', name, options) end def float(name, options={}) with_type('float', name, options) end def boolean(name, options={}) with_type('boolean', name, options) end def date(name, options={}) with_type('date', name, options) end def datetime(name, options={}) options[:typecast] = :xmlschema unless options.has_key?(:typecast) with_type('datetime', name, options) end alias_method :time, :datetime def with_type(type, name, options) (options[:attributes] ||= {}).merge!({:type => type}) options[:xmlsafe] = true unless options.has_key?(:xmlsafe) tag(name, options) end def array(name, options={}, &blk) options[:array] = self.class.new(&blk).config tag(name, options) end end end
Version data entries
13 entries across 13 versions & 1 rubygems