Class: Tataru::ResourceDsl
- Inherits:
-
Object
- Object
- Tataru::ResourceDsl
- Defined in:
- lib/tataru/resource_dsl.rb
Overview
human representation of resources
Constant Summary collapse
- REPCLASS =
Tataru::Representations::ResourceRepresentation
Instance Method Summary collapse
-
#initialize(name, desc) ⇒ ResourceDsl
constructor
A new instance of ResourceDsl.
- #method_missing(name, *args, &block) ⇒ Object
- #representation ⇒ Object
- #respond_to_missing?(name, *_args) ⇒ Boolean
Constructor Details
#initialize(name, desc) ⇒ ResourceDsl
Returns a new instance of ResourceDsl.
8 9 10 11 12 13 14 |
# File 'lib/tataru/resource_dsl.rb', line 8 def initialize(name, desc) @properties = {} @desc = desc @fields = Set.new(@desc.mutable_fields + @desc.immutable_fields) @name = name @dependencies = Set.new end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/tataru/resource_dsl.rb', line 20 def method_missing(name, *args, &block) return super unless @fields.include? name resolver = Resolver.new(args[0]) @dependencies += resolver.dependencies @properties[name] = if resolver.representation.is_a? REPCLASS resolver.representation.remote_id else resolver.representation end end |
Instance Method Details
#representation ⇒ Object
32 33 34 |
# File 'lib/tataru/resource_dsl.rb', line 32 def representation REPCLASS.new(@name, @desc, @properties) end |
#respond_to_missing?(name, *_args) ⇒ Boolean
16 17 18 |
# File 'lib/tataru/resource_dsl.rb', line 16 def respond_to_missing?(name, *_args) true if @fields.include? name end |