Class: Atum::Core::Schema::LinkSchema

Inherits:
Object
  • Object
show all
Defined in:
lib/atum/core/schema/link_schema.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_schema, resource_schema, link_schema_hash) ⇒ LinkSchema

link belongs to.

Parameters:

  • api_schema (ApiSchema)

    The schema for the whole API

  • resource_schema (ResourceSchema)

    The schema of the resource this

  • link_schema (Hash)

    The link’s schema



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_schemaObject (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

Parameters:

  • params (Array)

    The list of parameters to inject into the path.

Returns:

  • (String, Object)

    A path and request body pair. The body value is nil if a payload wasn’t included in the list of parameters.

Raises:

  • (ArgumentError)

    Raised if either too many or too few parameters were provided.



55
56
57
58
59
60
61
62
63
64
# 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

  params.map! { |param| URI.escape(param) }

  href.gsub(PARAMETER_REGEX) { |_match| format_parameter(params.shift) }
end

#descriptionObject



21
22
23
# File 'lib/atum/core/schema/link_schema.rb', line 21

def description
  @link_schema_hash['description']
end

#methodObject



25
26
27
# File 'lib/atum/core/schema/link_schema.rb', line 25

def method
  @link_schema_hash['method'].downcase.to_sym
end

#nameObject



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

Returns:

  • (Boolean)


29
30
31
# File 'lib/atum/core/schema/link_schema.rb', line 29

def needs_request_body?
  @link_schema_hash.key?('schema')
end

#parametersArray<Parameter|ParameterChoice>

Get the parameters this link expects.

Parameters:

  • parameters (Array)

    The names of the parameter definitions to convert to parameter names.

Returns:

  • (Array<Parameter|ParameterChoice>)

    A list of parameter instances that represent parameters to be injected into the link URL.



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