lib/sunspot/dsl/fields.rb in outoftime-sunspot-0.7.3 vs lib/sunspot/dsl/fields.rb in outoftime-sunspot-0.8.0

- old
+ new

@@ -1,7 +1,7 @@ module Sunspot - module DSL + module DSL #:nodoc: # The Fields class provides a DSL for specifying field definitions in the # Sunspot.setup block. As well as the #text method, which creates fulltext # fields, uses #method_missing to allow definition of typed fields. The # available methods are determined by the constants defined in # Sunspot::Type - in theory (though this is untested), plugin developers @@ -21,11 +21,11 @@ # # names...<Symbol>:: One or more field names # def text(*names, &block) for name in names - @setup.add_text_fields(build_field(name, Type::TextType, &block)) + @setup.add_text_fields(Field::StaticField.build(name, Type::TextType, &block)) end end # method_missing is used to provide access to typed fields, because # developers should be able to add new Sunspot::Type implementations @@ -41,29 +41,18 @@ # # The call to +time+ will create a field of type Sunspot::Types::TimeType # def method_missing(method, *args, &block) begin - type = Type.const_get("#{Util.camel_case(method.to_s)}Type") + type = Type.const_get("#{Util.camel_case(method.to_s.sub(/^dynamic_/, ''))}Type") rescue(NameError) super(method.to_sym, *args, &block) and return end name = args.shift - @setup.add_fields(build_field(name, type, *args, &block)) - end - - private - - # Factory method for field instances, used by the public methods in this - # class. Create a VirtualField if a block is passed, or an AttributeField - # if not. - # - def build_field(name, type, *args, &block) #:nodoc: - options = args.shift if args.first.is_a?(Hash) - unless block - Field::AttributeField.new(name, type, options || {}) + if method.to_s =~ /^dynamic_/ + @setup.add_dynamic_fields(Field::DynamicField.build(name, type, *args, &block)) else - Field::VirtualField.new(name, type, options || {}, &block) + @setup.add_fields(Field::StaticField.build(name, type, *args, &block)) end end end end end