Class: Tataru::Representations::ResourceRepresentation

Inherits:
Tataru::Representation show all
Defined in:
lib/tataru/representations/resource_representation.rb

Overview

internal representation of resources

Instance Attribute Summary collapse

Attributes inherited from Tataru::Representation

#value

Instance Method Summary collapse

Constructor Details

#initialize(name, desc, properties) ⇒ ResourceRepresentation

Returns a new instance of ResourceRepresentation.



9
10
11
12
13
14
# File 'lib/tataru/representations/resource_representation.rb', line 9

def initialize(name, desc, properties)
  @name = name
  @properties = properties
  @desc = desc
  check_late_deletability!
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object



38
39
40
41
42
# File 'lib/tataru/representations/resource_representation.rb', line 38

def method_missing(name, *args, &block)
  return super unless @desc.output_fields.include? name

  OutputRepresentation.new(@name, name)
end

Instance Attribute Details

#descObject (readonly)

Returns the value of attribute desc.



7
8
9
# File 'lib/tataru/representations/resource_representation.rb', line 7

def desc
  @desc
end

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/tataru/representations/resource_representation.rb', line 7

def name
  @name
end

#propertiesObject (readonly)

Returns the value of attribute properties.



7
8
9
# File 'lib/tataru/representations/resource_representation.rb', line 7

def properties
  @properties
end

Instance Method Details

#check_late_deletability!Object



16
17
18
19
20
# File 'lib/tataru/representations/resource_representation.rb', line 16

def check_late_deletability!
  return unless @desc.delete_at_end? && !@desc.needs_remote_id?

  raise 'must need remote id if deletes at end'
end

#check_required_fields!Object



22
23
24
25
26
27
28
# File 'lib/tataru/representations/resource_representation.rb', line 22

def check_required_fields!
  @desc.required_fields.each do |field|
    next if @properties.key? field

    raise "Required field '#{field}' not provided in '#{@name}'"
  end
end

#dependenciesObject



44
45
46
# File 'lib/tataru/representations/resource_representation.rb', line 44

def dependencies
  [@name]
end

#remote_idObject



34
35
36
# File 'lib/tataru/representations/resource_representation.rb', line 34

def remote_id
  OutputRepresentation.new(@name, :remote_id)
end

#respond_to_missing?(name, *_args) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/tataru/representations/resource_representation.rb', line 30

def respond_to_missing?(name, *_args)
  true if @desc.output_fields.include? name
end