module Maven::Tools::DSL::Options
Public Instance Methods
args_and_options( *args )
click to toggle source
# File lib/maven/tools/dsl/options.rb, line 26 def args_and_options( *args ) if args.last.is_a? Hash [ args[0..-2], args.last ] else [ args, {} ] end end
fill_options( receiver, options, *allow_defaults )
click to toggle source
# File lib/maven/tools/dsl/options.rb, line 34 def fill_options( receiver, options, *allow_defaults ) options.each do |k,v| if ! allow_defaults.member?( k ) && receiver.send( "#{k}".to_sym ) raise "#{receiver} has attribute #{k} already set" end receiver.send( "#{k}=".to_sym, v ) end end
help( name, *args )
click to toggle source
# File lib/maven/tools/dsl/options.rb, line 43 def help( name, *args ) args, options = args_and_options( *args ) args.each do |a| options[ a ] = a.to_s if a && !options.key?( a ) end opts = options.select{ |k,v| v } t = "\n# " + name.to_s.upcase + " #\n\n" unless opts.empty? t += "hash options: #{name} #{opts.inspect.gsub( /\"[{]/, '(' ).gsub( /[}]\"/, ')' )}\n" end t += "nested: #{name} do\n" t = append_nested_block( options, t ) t += " end\n" t end
help_block( *args )
click to toggle source
# File lib/maven/tools/dsl/options.rb, line 59 def help_block( *args ) args, options = help_args_and_options( *args ) append_nested_block( options ) end
Private Instance Methods
append_nested_block( options, t = "")
click to toggle source
# File lib/maven/tools/dsl/options.rb, line 74 def append_nested_block( options, t = "") options.each do |k,v| if v t += " #{k} #{v.inspect.gsub( /\"[{]/, '(' ).gsub( /[}]\"/, ')' )}\n" else t += " #{k} # nested element\n" end end t end
help_args_and_options( *args )
click to toggle source
# File lib/maven/tools/dsl/options.rb, line 66 def help_args_and_options( *args ) args, options = args_and_options( *args ) args.each do |a| options[ a ] = a.to_s if a && !options.key?( a ) end [ args, options ] end