Module: Rake::Opt::KeywordArgs::InstanceMethods
- Defined in:
- lib/rake/opt/keyword_args.rb
Instance Attribute Summary collapse
-
#arg_options ⇒ Object
Returns the value of attribute arg_options.
Instance Method Summary collapse
- #arg_hash_to_str(hash) ⇒ Object
- #parse_args(args) ⇒ Object
- #verify_and_merge_args(args) ⇒ Object
- #verify_args(args) ⇒ Object
Instance Attribute Details
#arg_options ⇒ Object
Returns the value of attribute arg_options.
90 91 92 |
# File 'lib/rake/opt/keyword_args.rb', line 90 def @arg_options end |
Instance Method Details
#arg_hash_to_str(hash) ⇒ Object
151 152 153 154 155 |
# File 'lib/rake/opt/keyword_args.rb', line 151 def arg_hash_to_str(hash) args = '' hash.each{ |k, v| args << "#{k}=#{v} " } return args.strip end |
#parse_args(args) ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/rake/opt/keyword_args.rb', line 92 def parse_args(args) raise Error, 'Expected only one argument' if args.count > 1 args = (args.first && args.first.last) ? args.first.last : '' parsed_args = Hashie::Mash.new args.split(PARAM_SEPARATOR).each do |pair| arg, value = pair.split('=', 2) parsed_args[arg] = value.blank? ? nil : value end return parsed_args end |
#verify_and_merge_args(args) ⇒ Object
146 147 148 149 |
# File 'lib/rake/opt/keyword_args.rb', line 146 def verify_and_merge_args(args) verified = verify_args(args) return self.parse_args(args).merge(verified) end |
#verify_args(args) ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/rake/opt/keyword_args.rb', line 104 def verify_args(args) return args unless self. parsed_args = self.parse_args(args) output = Hashie::Mash.new self..each do |arg_name, | # Extract Value if it's set, otherwise, use the default if parsed_args[arg_name] value = parsed_args[arg_name] else value = [:default] end # Cast the argument to the proper type if value.nil? # Keep it as nil elsif [Fixnum, Integer].include? [:class] value = value.to_i elsif Float == [:class] value = value.to_f elsif Symbol == [:class] value = value.to_sym elsif Rational == [:class] value = value.to_r elsif [String, nil].include? [:class] value = value.to_s elsif Boolean == [:class] value = %w{ 1 true yes t }.include? value.to_s.downcase else raise UnsupportedTypeError, "Arguments of type #{[:class]} are not supported" end # Set the output value output[arg_name] = value if [:required] && output[arg_name].nil? && !Rake.application..dryrun raise ValidationError, "Argument :#{arg_name} is required for Task #{self.name}" end end return output end |