Object
A class responsible for handilng request arguments
Initialize an Arguments
@param [Hash] options
@option options [Array] :required
arguments that must be present before request is fired
@option options [Github::API] :api
the reference to the current api
@api public
# File lib/github_api/api/arguments.rb, line 32 def initialize(options = {}, &block) normalize! options @api = options.fetch('api') @required = options.fetch('required', []).map(&:to_s) @optional = options.fetch('optional', []).map(&:to_s) @assigns = {} yield_or_eval(&block) end
Hash like access to request arguments
@param [String, Symbol] property
the property name
@api public
# File lib/github_api/api/arguments.rb, line 65 def [](property) @assigns[property.to_s] end
# File lib/github_api/api/arguments.rb, line 69 def []=(property, value) @assigns[property.to_s] = value end
Check if required keys are present inside parameters hash.
@api public
# File lib/github_api/api/arguments.rb, line 120 def assert_required(required) assert_required_keys required, params self end
Check if parameters match expected values.
@api public
# File lib/github_api/api/arguments.rb, line 128 def assert_values(values, key=nil) assert_valid_values values, (key.nil? ? params : params[key]) self end
# File lib/github_api/api/arguments.rb, line 73 def method_missing(method_name, *args, &block) if @assigns.key?(method_name.to_s) self[method_name] else super end end
Specify optional attribute(s)
@api public
# File lib/github_api/api/arguments.rb, line 56 def optional(*attrs, &block) end
Parse arguments to allow for flexible api calls
Arguments can be part of parameters hash or be simple string arguments.
@api public
# File lib/github_api/api/arguments.rb, line 90 def parse(*args, &block) options = ParamsHash.new(args.extract_options!) normalize! options if args.size.zero? # Arguments are inside the parameters hash parse_hash(options) else parse_array(*args) end @params = options @remaining = args[@required.size..-1] extract_pagination(options) yield_or_eval(&block) self end
Remove unknown keys from parameters hash.
:recursive - boolean that toggles whether nested filtering should be applied
# File lib/github_api/api/arguments.rb, line 112 def permit(keys, key=nil, options={}) filter! keys, (key.nil? ? params : params[key]), options if keys.any? self end
Specify required attribute(s)
@api public
# File lib/github_api/api/arguments.rb, line 46 def require(*attrs, &block) attrs_clone = attrs.clone @required = Array(attrs_clone) self end
Generated with the Darkfish Rdoc Generator 2.