Class: RabbitMQSpec::DSL::Builder::Base Private
- Inherits:
-
Object
- Object
- RabbitMQSpec::DSL::Builder::Base
- Defined in:
- lib/rabbitmq-spec/dsl/builder/base.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Base class for each builder. A Builder is a class where the DSL evaluator will run the DSL files. It is where we define our DSL syntax. For more info to know how to use it, see the specs related to the builders.
Defined Under Namespace
Classes: HashBuilder
Class Method Summary collapse
-
.build(default_entity_values = {}, &block) ⇒ void
private
This method evaluates the given blog inside a new instance of the Builder class and asks for the class to build the correlated entity.
Instance Method Summary collapse
- #build_entity ⇒ void private
-
#initialize(default_entity_values = {}) ⇒ Base
constructor
private
instance methods.
-
#method_missing(method_name, *args, &block) ⇒ void
private
For each method called we verify if it's an defined attribute for the builder.
Constructor Details
#initialize(default_entity_values = {}) ⇒ Base
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
instance methods
49 50 51 |
# File 'lib/rabbitmq-spec/dsl/builder/base.rb', line 49 def initialize(default_entity_values = {}) @builded_attributes = {}.merge(default_entity_values) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
For each method called we verify if it's an defined attribute for the builder. If it is then we store the argument as value of the attribute
56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/rabbitmq-spec/dsl/builder/base.rb', line 56 def method_missing(method_name, *args, &block) if self.class.has_dsl_attribute?(method_name.to_sym) @builded_attributes[method_name.to_sym] = if block_given? build_hash_from_block(&block) else args[0] end else raise "Configuration '#{method_name}' is not allowed for #{self}" end end |
Class Method Details
.build(default_entity_values = {}, &block) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method evaluates the given blog inside a new instance of the Builder class and asks for the class to build the correlated entity
42 43 44 45 46 |
# File 'lib/rabbitmq-spec/dsl/builder/base.rb', line 42 def self.build(default_entity_values = {}, &block) builder = new(default_entity_values) builder.instance_eval(&block) builder.build_entity end |
Instance Method Details
#build_entity ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
68 69 70 71 72 73 74 75 |
# File 'lib/rabbitmq-spec/dsl/builder/base.rb', line 68 def build_entity raise "Entity class is not defined for #{self.class}" if self.class.get_entity_class.nil? entity = self.class.get_entity_class.new @builded_attributes.each_pair do |k, v| entity.send("#{k}=", v) end entity end |