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(sc_resource_handle) ⇒ Resource

Returns a new instance of Resource.

Parameters:

  • sc_resource_handle (FFI::Pointer)


335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
# File 'lib/redsnow/blueprint.rb', line 335

def initialize(sc_resource_handle)
  @name = RedSnow::Binding.sc_resource_name(sc_resource_handle)
  @description = RedSnow::Binding.sc_resource_description(sc_resource_handle)
  @uri_template = RedSnow::Binding.sc_resource_uritemplate(sc_resource_handle)

  sc_payload_handle_resource = RedSnow::Binding.sc_payload_handle_resource(sc_resource_handle)
  @model = Payload.new(sc_payload_handle_resource)

  @parameters = Parameters.new(RedSnow::Binding.sc_parameter_collection_handle_resource(sc_resource_handle))

  @actions = []
  sc_action_collection_handle = RedSnow::Binding.sc_action_collection_handle(sc_resource_handle)
  sc_action_collection_size = RedSnow::Binding.sc_action_collection_size(sc_action_collection_handle)

  return if sc_action_collection_size == 0

  action_size = sc_action_collection_size - 1

  (0..action_size).each do |index|
    sc_action_handle = RedSnow::Binding.sc_action_handle(sc_action_collection_handle, index)
    @actions << Action.new(sc_action_handle).tap do |action|
      resource_instance = self
      action.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



328
329
330
# File 'lib/redsnow/blueprint.rb', line 328

def actions
  @actions
end

#modelModel

model payload for the resource or nil

Returns:

  • (Model)

    the current value of model



328
329
330
# File 'lib/redsnow/blueprint.rb', line 328

def model
  @model
end

#parametersParameters

action-specific URI parameters or nil

Returns:

  • (Parameters)

    the current value of parameters



328
329
330
# File 'lib/redsnow/blueprint.rb', line 328

def parameters
  @parameters
end

#uri_templateString

RFC 6570 URI template

Returns:

  • (String)

    the current value of uri_template



328
329
330
# File 'lib/redsnow/blueprint.rb', line 328

def uri_template
  @uri_template
end