Class: Tataru::Representations::ResourceRepresentation
- Inherits:
-
Tataru::Representation
- Object
- Tataru::Representation
- Tataru::Representations::ResourceRepresentation
- Defined in:
- lib/tataru/representations/resource_representation.rb
Overview
internal representation of resources
Instance Attribute Summary collapse
-
#desc ⇒ Object
readonly
Returns the value of attribute desc.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#properties ⇒ Object
readonly
Returns the value of attribute properties.
Attributes inherited from Tataru::Representation
Instance Method Summary collapse
- #check_late_deletability! ⇒ Object
- #check_required_fields! ⇒ Object
- #dependencies ⇒ Object
-
#initialize(name, desc, properties) ⇒ ResourceRepresentation
constructor
A new instance of ResourceRepresentation.
- #method_missing(name, *args, &block) ⇒ Object
- #remote_id ⇒ Object
- #respond_to_missing?(name, *_args) ⇒ Boolean
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
#desc ⇒ Object (readonly)
Returns the value of attribute desc.
7 8 9 |
# File 'lib/tataru/representations/resource_representation.rb', line 7 def desc @desc end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/tataru/representations/resource_representation.rb', line 7 def name @name end |
#properties ⇒ Object (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 |
#dependencies ⇒ Object
44 45 46 |
# File 'lib/tataru/representations/resource_representation.rb', line 44 def dependencies [@name] end |
#remote_id ⇒ Object
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
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 |