Class: Atum::Core::Schema::LinkSchema
- Inherits:
-
Object
- Object
- Atum::Core::Schema::LinkSchema
- Defined in:
- lib/atum/core/schema/link_schema.rb
Instance Attribute Summary collapse
-
#resource_schema ⇒ Object
readonly
Returns the value of attribute resource_schema.
Instance Method Summary collapse
-
#construct_path(*params) ⇒ String, Object
Construct the URL and body for a call to this link.
- #description ⇒ Object
-
#initialize(api_schema, resource_schema, link_schema_hash) ⇒ LinkSchema
constructor
link belongs to.
- #method ⇒ Object
- #name ⇒ Object
- #needs_request_body? ⇒ Boolean
-
#parameters ⇒ Array<Parameter|ParameterChoice>
Get the parameters this link expects.
Constructor Details
#initialize(api_schema, resource_schema, link_schema_hash) ⇒ LinkSchema
link belongs to.
11 12 13 14 15 |
# File 'lib/atum/core/schema/link_schema.rb', line 11 def initialize(api_schema, resource_schema, link_schema_hash) @api_schema = api_schema @resource_schema = resource_schema @link_schema_hash = link_schema_hash end |
Instance Attribute Details
#resource_schema ⇒ Object (readonly)
Returns the value of attribute resource_schema.
5 6 7 |
# File 'lib/atum/core/schema/link_schema.rb', line 5 def resource_schema @resource_schema end |
Instance Method Details
#construct_path(*params) ⇒ String, Object
Construct the URL and body for a call to this link
55 56 57 58 59 60 61 62 |
# File 'lib/atum/core/schema/link_schema.rb', line 55 def construct_path(*params) if expected_params.count != params.count raise ArgumentError, "Wrong number of arguments: #{params.count} " \ "for #{expected_params.count}" end href.gsub(PARAMETER_REGEX) { |_match| format_parameter(params.shift) } end |
#description ⇒ Object
21 22 23 |
# File 'lib/atum/core/schema/link_schema.rb', line 21 def description @link_schema_hash['description'] end |
#method ⇒ Object
25 26 27 |
# File 'lib/atum/core/schema/link_schema.rb', line 25 def method @link_schema_hash['method'].downcase.to_sym end |
#name ⇒ Object
17 18 19 |
# File 'lib/atum/core/schema/link_schema.rb', line 17 def name @link_schema_hash['title'].downcase.gsub(' ', '_') end |
#needs_request_body? ⇒ Boolean
29 30 31 |
# File 'lib/atum/core/schema/link_schema.rb', line 29 def needs_request_body? @link_schema_hash.key?('schema') end |
#parameters ⇒ Array<Parameter|ParameterChoice>
Get the parameters this link expects.
39 40 41 42 43 44 45 |
# File 'lib/atum/core/schema/link_schema.rb', line 39 def parameters expected_params.map do |parameter| # URI decode parameters and strip the leading '{(' and trailing ')}'. parameter = URI.unescape(parameter[2..-3]) generate_parameter(parameter) end end |