lib/rake/funnel/support/mapper.rb in rake-funnel-0.3.2.pre vs lib/rake/funnel/support/mapper.rb in rake-funnel-0.4.0.pre

- old
+ new

@@ -1,53 +1,57 @@ -Dir[File.join(File.dirname(__FILE__), 'argument_mapper', '*.rb')].each do |path| - require path -end - -module Rake::Funnel::Support - class Mapper - include Rake::Funnel::Support::ArgumentMapper - include InstantiateSymbol - instantiate Styles - - def initialize(style = :Default) - raise "You cannot use the 'nil' mapper style. Available mappers are: #{available.inspect}" if style.nil? - - @style = create(style) - end - - def map(args = {}) - model = (args || {}).map { |switch, value| - value = [value] unless value.kind_of?(Array) - - values = value.map do |val| - get_values(val) - end - - Switch.new(switch, values) - }.flatten - - @style - .generate_from(model) - .map { |args| args.map { |arg| camel_case_symbols(arg) }} - .map(&:join) - end - - private - def get_values(value) - if value.kind_of?(Enumerable) - pairs = value.map { |k, v| - KeyValuePair.new(k, v) - } - - return Array.new(pairs) if value.kind_of?(Array) - pairs - else - Value.new(value) - end - end - - def camel_case_symbols(value) - return value unless value.kind_of?(Symbol) - value.camelize - end - end -end +Dir[File.join(File.dirname(__FILE__), 'argument_mapper', '*.rb')].each do |path| + require path +end + +module Rake + module Funnel + module Support + class Mapper + include ArgumentMapper + include InstantiateSymbol + instantiate Styles + + def initialize(style = :Default) + raise "You cannot use the 'nil' mapper style. Available mappers are: #{available.inspect}" if style.nil? + + @style = create(style) + end + + def map(args = {}) + model = (args || {}).map { |switch, value| + value = [value] unless value.is_a?(Array) + + values = value.map do |val| + get_values(val) + end + + Switch.new(switch, values) + }.flatten + + @style + .generate_from(model) + .map { |args| args.map { |arg| camel_case_symbols(arg) } } + .map(&:join) + end + + private + def get_values(value) + if value.is_a?(Enumerable) + pairs = value.map { |k, v| + KeyValuePair.new(k, v) + } + + return Array.new(pairs) if value.is_a?(Array) + pairs + else + Value.new(value) + end + end + + def camel_case_symbols(value) + return value unless value.is_a?(Symbol) + value.camelize + end + end + end + end +end