lib/rake/funnel/support/mapper.rb in rake-funnel-0.0.6.pre vs lib/rake/funnel/support/mapper.rb in rake-funnel-0.1.0.pre
- old
+ new
@@ -1,46 +1,18 @@
-Dir["#{File.dirname(__FILE__)}/mapper_styles/*.rb"].each do |path|
+Dir[File.join(File.dirname(__FILE__), 'argument_mapper', '*.rb')].each do |path|
require path
end
module Rake::Funnel::Support
- class Switch
- attr_reader :switch, :values
-
- def initialize(switch, values)
- @values = values
- @switch = switch
- end
- end
-
- class Value
- attr_reader :key, :value
-
- def initialize(value)
- @key = nil
- @value = value
- end
- end
-
- class KeyValuePair
- attr_reader :key, :value
-
- def initialize(key, value)
- @key = key
- @value = value
- end
- end
-
class Mapper
+ include Rake::Funnel::Support::ArgumentMapper
+ include InstantiateSymbol
+ instantiate Styles
+
def initialize(style = :Default)
- raise "You cannot use a 'nil' mapper. Available mappers are: #{MapperStyles.constants.sort.join(', ')}" if style.nil?
+ raise "You cannot use the 'nil' mapper style. Available mappers are: #{available.inspect}" if style.nil?
- @style = style
- begin
- @style = MapperStyles.const_get(style).new if style.kind_of?(Symbol)
- rescue => ex
- raise "Something went wrong while creating the '#{style}' mapper: #{ex}"
- end
+ @style = create(style)
end
def map(args = {})
model = (args || {}).map { |switch, value|
value = [value] unless value.kind_of?(Array)