Class: AwDatapipe::PipelineObject
- Inherits:
-
Struct
- Object
- Struct
- AwDatapipe::PipelineObject
- Defined in:
- lib/aw_datapipe/pipeline_object.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#name ⇒ Object
Returns the value of attribute name.
-
#pipeline ⇒ Object
Returns the value of attribute pipeline.
Class Method Summary collapse
Instance Method Summary collapse
-
#dependencies ⇒ Object
Iterates through struct members, recursively collecting any PipelineObjects.
-
#initialize(params) ⇒ PipelineObject
constructor
A new instance of PipelineObject.
- #inspect ⇒ Object
- #source(indent_level = 1) ⇒ Object
- #to_hash ⇒ Object
- #type ⇒ Object
Constructor Details
#initialize(params) ⇒ PipelineObject
Returns a new instance of PipelineObject.
11 12 13 14 15 |
# File 'lib/aw_datapipe/pipeline_object.rb', line 11 def initialize(params) @id = params.delete(:id) || params[:name].underscore.to_sym || raise(ArgumentError, ":id or :name required: #{params.inspect}") params.each_pair { |k, v| send "#{k}=", v } end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
3 4 5 |
# File 'lib/aw_datapipe/pipeline_object.rb', line 3 def id @id end |
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/aw_datapipe/pipeline_object.rb', line 4 def name @name end |
#pipeline ⇒ Object
Returns the value of attribute pipeline.
5 6 7 |
# File 'lib/aw_datapipe/pipeline_object.rb', line 5 def pipeline @pipeline end |
Class Method Details
.build(params) ⇒ Object
7 8 9 |
# File 'lib/aw_datapipe/pipeline_object.rb', line 7 def self.build(params) new(params) end |
Instance Method Details
#dependencies ⇒ Object
Iterates through struct members, recursively collecting any PipelineObjects. Recursion ensures dependencies sorted before dependents.
19 20 21 22 23 24 25 |
# File 'lib/aw_datapipe/pipeline_object.rb', line 19 def dependencies members.each_with_object([]) do |attr_name, depends| value = send(attr_name) value = pipeline.objects.fetch(value) if value.is_a?(Symbol) depends << value.dependencies << value if value.is_a?(PipelineObject) end.flatten end |
#inspect ⇒ Object
27 28 29 |
# File 'lib/aw_datapipe/pipeline_object.rb', line 27 def inspect "#<#{type} #{to_hash}>" end |
#source(indent_level = 1) ⇒ Object
35 36 37 38 39 |
# File 'lib/aw_datapipe/pipeline_object.rb', line 35 def source(indent_level = 1) "#{self.class.name}.build(" << [:id, :name, *members].map do |member| "\n" << indent(indent_level) << member_source(member) end.join(",") << ")" end |
#to_hash ⇒ Object
31 32 33 |
# File 'lib/aw_datapipe/pipeline_object.rb', line 31 def to_hash Hash[each_pair.select { |k, v| v != nil }].merge(id: id, name: name) end |
#type ⇒ Object
41 42 43 |
# File 'lib/aw_datapipe/pipeline_object.rb', line 41 def type self.class.name.split('::').last end |