Class: Pipelines::Configuration::Item

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
app/pipelines/pipelines/configuration.rb

Overview

Configuration::Item TODO: this needs fixing. It is being used in slightly different ways and we should be able to iterate rather than map.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pipeline, children = {}) ⇒ Item

builds a configuration item object This is a recursive function for each child that is a hash it will create a new Configuration::Item This creates a chain of instance methods for each item in the hash It also creates an attribute reader of the original hash.

Parameters:

  • children (Hash) (defaults to: {})

    list of all the pipelines with their respective configuration



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'app/pipelines/pipelines/configuration.rb', line 34

def initialize(pipeline, children = {})
  @children = children

  # the pipeline tells you which pipeline it belongs to without having
  # to query the class itself. I know it is only useful for tests but
  # worth it
  @pipeline = pipeline

  children.each do |key, child|
    if child.instance_of?(ActiveSupport::HashWithIndifferentAccess)
      next if respond_to?(key)

      child_item = Item.new(pipeline, child)
      define_singleton_method(key) { child_item }
    else
      define_singleton_method(key) { child }
    end
  end
end

Instance Attribute Details

#childrenObject (readonly)

Returns the value of attribute children.



26
27
28
# File 'app/pipelines/pipelines/configuration.rb', line 26

def children
  @children
end

#pipelineObject (readonly)

Returns the value of attribute pipeline.



26
27
28
# File 'app/pipelines/pipelines/configuration.rb', line 26

def pipeline
  @pipeline
end

Instance Method Details

#by_version(version) ⇒ Object

Return the version of the item Check if it is a valid version type as per Version::FORMAT Otherwise raise an error



61
62
63
64
65
66
67
68
# File 'app/pipelines/pipelines/configuration.rb', line 61

def by_version(version)
  unless version.match(Version::FORMAT) && respond_to?(version)
    raise Version::Error,
          "SMRTLink sample sheet (#{version}) is not supported or invalid"
  end

  send(version)
end

#eachObject



54
55
56
# File 'app/pipelines/pipelines/configuration.rb', line 54

def each(...)
  children.each(...)
end