Class: RedSnow::Resource

Inherits:
NamedBlueprintNode show all
Defined in:
lib/redsnow/blueprint.rb

Overview

Resource Blueprint AST node

represents 'resource section'

Instance Attribute Summary collapse

Attributes inherited from NamedBlueprintNode

#description, #name

Instance Method Summary collapse

Methods inherited from NamedBlueprintNode

#ensure_description_newlines

Constructor Details

#initialize(resource) ⇒ Resource

Returns a new instance of Resource.

Parameters:

  • resource (json)


300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
# File 'lib/redsnow/blueprint.rb', line 300

def initialize(resource)
  @name = resource.fetch('name', '')
  @description = resource.fetch('description', '')
  @uri_template = resource.fetch('uriTemplate', '')

  @model = Payload.new(resource.fetch('model', nil))

  @parameters = Parameters.new(resource.fetch('parameters', nil))

  @actions = []
  resource.key?('actions') && resource['actions'].each do |action|
    @actions << Action.new(action).tap do |inst|
      resource_instance = self
      inst.define_singleton_method(:resource) { resource_instance }
    end
  end
end

Instance Attribute Details

#actionsArray<Action>

array of resource actions or nil

Returns:

  • (Array<Action>)

    the current value of actions



293
294
295
# File 'lib/redsnow/blueprint.rb', line 293

def actions
  @actions
end

#modelModel

model payload for the resource or nil

Returns:

  • (Model)

    the current value of model



293
294
295
# File 'lib/redsnow/blueprint.rb', line 293

def model
  @model
end

#parametersParameters

action-specific URI parameters or nil

Returns:

  • (Parameters)

    the current value of parameters



293
294
295
# File 'lib/redsnow/blueprint.rb', line 293

def parameters
  @parameters
end

#uri_templateString

RFC 6570 URI template

Returns:

  • (String)

    the current value of uri_template



293
294
295
# File 'lib/redsnow/blueprint.rb', line 293

def uri_template
  @uri_template
end