Class: Github::Arguments
- Inherits:
-
Object
- Object
- Github::Arguments
- Includes:
- Normalizer, ParameterFilter, Validations
- Defined in:
- lib/github_api/arguments.rb
Overview
Request arguments handler
Constant Summary collapse
- AUTO_PAGINATION =
'auto_pagination'.freeze
Constants included from Validations
Constants included from Validations::Token
Validations::Token::TOKEN_REQUIRED, Validations::Token::TOKEN_REQUIRED_REGEXP
Instance Attribute Summary collapse
-
#api ⇒ Object
readonly
The request api.
-
#params ⇒ Object
readonly
Parameters passed to request.
-
#remaining ⇒ Object
readonly
Returns the value of attribute remaining.
Instance Method Summary collapse
-
#assert_required(required) ⇒ Object
Check if required keys are present inside parameters hash.
-
#assert_values(values, key = nil) ⇒ Object
Check if parameters match expected values.
-
#initialize(api, options = {}) ⇒ Arguments
constructor
Takes api, filters and required arguments.
-
#parse(*args, &block) ⇒ Object
Parse arguments to allow for flexible api calls.
-
#sift(keys, key = nil, options = {}) ⇒ Object
Remove unkown keys from parameters hash.
Methods included from Validations::Required
Methods included from Validations::Token
Methods included from Validations::Format
Methods included from Validations::Presence
Methods included from ParameterFilter
Methods included from Normalizer
Constructor Details
#initialize(api, options = {}) ⇒ Arguments
Takes api, filters and required arguments
Parameters
:required - arguments that must be present before request is fired
37 38 39 40 41 42 |
# File 'lib/github_api/arguments.rb', line 37 def initialize(api, ={}) normalize! @api = api @required = .fetch('required', []).map(&:to_s) @optional = .fetch('optional', []).map(&:to_s) end |
Instance Attribute Details
#api ⇒ Object (readonly)
The request api
20 21 22 |
# File 'lib/github_api/arguments.rb', line 20 def api @api end |
#params ⇒ Object (readonly)
Parameters passed to request
14 15 16 |
# File 'lib/github_api/arguments.rb', line 14 def params @params end |
#remaining ⇒ Object (readonly)
Returns the value of attribute remaining.
16 17 18 |
# File 'lib/github_api/arguments.rb', line 16 def remaining @remaining end |
Instance Method Details
#assert_required(required) ⇒ Object
Check if required keys are present inside parameters hash.
76 77 78 79 |
# File 'lib/github_api/arguments.rb', line 76 def assert_required(required) assert_required_keys required, params self end |
#assert_values(values, key = nil) ⇒ Object
Check if parameters match expected values.
83 84 85 86 |
# File 'lib/github_api/arguments.rb', line 83 def assert_values(values, key=nil) assert_valid_values values, (key.nil? ? params : params[key]) self end |
#parse(*args, &block) ⇒ Object
Parse arguments to allow for flexible api calls. Arguments can be part of parameters hash or be simple string arguments.
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/github_api/arguments.rb', line 47 def parse(*args, &block) = ParamsHash.new(args.) normalize! if !args.size.zero? parse_arguments *args else # Arguments are inside the parameters hash end @params = @remaining = extract_remaining(args) extract_pagination() yield_or_eval(&block) self end |
#sift(keys, key = nil, options = {}) ⇒ Object
Remove unkown keys from parameters hash.
Parameters
:recursive - boolean that toggles whether nested filtering should be applied
69 70 71 72 |
# File 'lib/github_api/arguments.rb', line 69 def sift(keys, key=nil, ={}) filter! keys, (key.nil? ? params : params[key]), if keys.any? self end |