Class: Brujula::TypeExtender::Resource
- Inherits:
-
Object
- Object
- Brujula::TypeExtender::Resource
- Defined in:
- lib/brujula/type_extender/resource.rb
Instance Attribute Summary collapse
-
#definition ⇒ Object
readonly
Returns the value of attribute definition.
Instance Method Summary collapse
- #apply_inherit_chain ⇒ Object
- #apply_traits(object) ⇒ Object
- #apply_traits_to_method(method) ⇒ Object
- #apply_type(object) ⇒ Object
- #call ⇒ Object
- #extended_object ⇒ Object
-
#initialize(definition:) ⇒ Resource
constructor
A new instance of Resource.
- #parameter_builder(object) ⇒ Object
- #parametized_trait(trait, method) ⇒ Object
- #parametized_type ⇒ Object
Constructor Details
#initialize(definition:) ⇒ Resource
Returns a new instance of Resource.
6 7 8 |
# File 'lib/brujula/type_extender/resource.rb', line 6 def initialize(definition:) @definition = definition end |
Instance Attribute Details
#definition ⇒ Object (readonly)
Returns the value of attribute definition.
4 5 6 |
# File 'lib/brujula/type_extender/resource.rb', line 4 def definition @definition end |
Instance Method Details
#apply_inherit_chain ⇒ Object
20 21 22 23 24 25 |
# File 'lib/brujula/type_extender/resource.rb', line 20 def apply_inherit_chain object = definition.dup object = apply_type(object) unless definition.type.nil? object = apply_traits(object) unless definition.is.nil? object end |
#apply_traits(object) ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/brujula/type_extender/resource.rb', line 34 def apply_traits(object) return object if definition.methods.nil? object.methods.each do |method| new_method = apply_traits_to_method(method) object.methods.merge(new_method.name, new_method) end object end |
#apply_traits_to_method(method) ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/brujula/type_extender/resource.rb', line 44 def apply_traits_to_method(method) definition.is.inject(method.dup) do |object, trait| Brujula::Mergers::ObjectMerger.new( superinstance: parametized_trait(trait, object), instance: object ).call end end |
#apply_type(object) ⇒ Object
27 28 29 30 31 32 |
# File 'lib/brujula/type_extender/resource.rb', line 27 def apply_type(object) Brujula::Mergers::ObjectMerger.new( superinstance: parametized_type, instance: object, ).call end |
#call ⇒ Object
10 11 12 13 14 |
# File 'lib/brujula/type_extender/resource.rb', line 10 def call return definition if definition.type.nil? && definition.is.nil? extended_object end |
#extended_object ⇒ Object
16 17 18 |
# File 'lib/brujula/type_extender/resource.rb', line 16 def extended_object @extended_object ||= apply_inherit_chain end |
#parameter_builder(object) ⇒ Object
66 67 68 69 70 |
# File 'lib/brujula/type_extender/resource.rb', line 66 def parameter_builder(object) Brujula::Parameters::Builder.new( object: object ) end |
#parametized_trait(trait, method) ⇒ Object
52 53 54 55 56 57 |
# File 'lib/brujula/type_extender/resource.rb', line 52 def parametized_trait(trait, method) Brujula::Parameters::Parser.new( object: trait, parameters: parameter_builder(trait).method_params(definition, method) ).call end |
#parametized_type ⇒ Object
59 60 61 62 63 64 |
# File 'lib/brujula/type_extender/resource.rb', line 59 def parametized_type Brujula::Parameters::Parser.new( object: definition.type, parameters: parameter_builder(definition.type).resource_params(definition) ).call end |