Class: NationBuilder::Method
- Inherits:
-
Object
- Object
- NationBuilder::Method
- Defined in:
- lib/nationbuilder/method.rb
Instance Attribute Summary collapse
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#http_method ⇒ Object
readonly
Returns the value of attribute http_method.
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Instance Method Summary collapse
-
#initialize(name, http_method, uri, description) ⇒ Method
constructor
A new instance of Method.
- #method_args(args) ⇒ Object
- #name ⇒ Object
- #nonmethod_args(args) ⇒ Object
- #parameters ⇒ Object
- #register_parameter(parameter) ⇒ Object
- #validate_args(args) ⇒ Object
Constructor Details
#initialize(name, http_method, uri, description) ⇒ Method
Returns a new instance of Method.
5 6 7 8 9 10 11 |
# File 'lib/nationbuilder/method.rb', line 5 def initialize(name, http_method, uri, description) @name = name @http_method = http_method.downcase.to_sym @uri = uri @description = description @name_to_parameter = {} end |
Instance Attribute Details
#description ⇒ Object (readonly)
Returns the value of attribute description.
3 4 5 |
# File 'lib/nationbuilder/method.rb', line 3 def description @description end |
#http_method ⇒ Object (readonly)
Returns the value of attribute http_method.
3 4 5 |
# File 'lib/nationbuilder/method.rb', line 3 def http_method @http_method end |
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
3 4 5 |
# File 'lib/nationbuilder/method.rb', line 3 def uri @uri end |
Instance Method Details
#method_args(args) ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/nationbuilder/method.rb', line 32 def method_args(args) a = {} args.each do |k, v| a[k] = v if parameters.include?(k) end a end |
#name ⇒ Object
21 22 23 |
# File 'lib/nationbuilder/method.rb', line 21 def name @name.downcase.gsub(' ', '_').to_sym end |
#nonmethod_args(args) ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/nationbuilder/method.rb', line 40 def nonmethod_args(args) a = {} args.each do |k, v| a[k] = v unless parameters.include?(k) end a end |
#parameters ⇒ Object
17 18 19 |
# File 'lib/nationbuilder/method.rb', line 17 def parameters @name_to_parameter.keys end |
#register_parameter(parameter) ⇒ Object
13 14 15 |
# File 'lib/nationbuilder/method.rb', line 13 def register_parameter(parameter) @name_to_parameter[parameter.name] = parameter end |
#validate_args(args) ⇒ Object
25 26 27 28 29 30 |
# File 'lib/nationbuilder/method.rb', line 25 def validate_args(args) if Set.new(args.keys) != Set.new(parameters) raise ArgumentError .new("Required args: #{parameters.join(', ')}. Provided args: #{args.keys.join(', ')}") end end |