Class: Lono::Jade

Inherits:
Object
  • Object
show all
Extended by:
Memoist
Includes:
Circular
Defined in:
lib/lono/jade.rb,
lib/lono/jade/circular.rb,
lib/lono/jade/registry.rb,
lib/lono/jade/materializer.rb

Defined Under Namespace

Modules: Circular Classes: Materializer, Registry

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Circular

#check_for_circular_dependency!, #circular_dependency?, #parent_names

Constructor Details

#initialize(name, type, registry = {}) ⇒ Jade

Returns a new instance of Jade.



10
11
12
13
14
15
16
17
# File 'lib/lono/jade.rb', line 10

def initialize(name, type, registry={})
  # type: one of blueprint, configset, blueprint/configset
  # registry holds either original registry from configset definition or parent jade which can be used to get the original configset defintion
  @name, @type, @registry = name, type, registry
  @materialized = false
  @resolved = false
  @depends_ons = []
end

Instance Attribute Details

#dependenciesObject

Returns the value of attribute dependencies.



8
9
10
# File 'lib/lono/jade.rb', line 8

def dependencies
  @dependencies
end

#depends_onsObject

Returns the value of attribute depends_ons.



8
9
10
# File 'lib/lono/jade.rb', line 8

def depends_ons
  @depends_ons
end

#fromObject

Returns the value of attribute from.



8
9
10
# File 'lib/lono/jade.rb', line 8

def from
  @from
end

#jadespecObject (readonly)

Returns the value of attribute jadespec.



9
10
11
# File 'lib/lono/jade.rb', line 9

def jadespec
  @jadespec
end

#nameObject (readonly)

Returns the value of attribute name.



9
10
11
# File 'lib/lono/jade.rb', line 9

def name
  @name
end

#registryObject (readonly)

Returns the value of attribute registry.



9
10
11
# File 'lib/lono/jade.rb', line 9

def registry
  @registry
end

#typeObject (readonly)

Returns the value of attribute type.



9
10
11
# File 'lib/lono/jade.rb', line 9

def type
  @type
end

Instance Method Details

#downloadObject

Must return config to set @jadespec in materialize Only allow download of Lono::Blueprint::Configset::Jade Other configsets should be configured in project Gemfile.

Cases:

1a) blueprint/configset top-level - download
1b) blueprint/configset depends_on - download
2a) configset top-level - dont download, will report to user with validate_all!
2b) configset depends_on - download
3) extension - download


80
81
82
83
84
85
86
87
88
# File 'lib/lono/jade.rb', line 80

def download
  return if finder.find(@name, local_only: true) # no need to download because locally found
  return unless %w[blueprint/configset configset extension].include?(@type)
  # Comment out. Unsure if this complexity is worth it. Always download jades.
  # Only download jades that came from depends_on
  # return unless @registry.parent || %w[blueprint/configset extension].include?(@type)
  materializer = Materializer.new(self)
  materializer.build
end

#evaluate_meta_rbObject



91
92
93
94
95
# File 'lib/lono/jade.rb', line 91

def evaluate_meta_rb
  return unless %w[blueprint/configset configset].include?(@type)
  meta = Lono::Configset::Meta.new(self)
  meta.evaluate
end

#finderObject



105
106
107
# File 'lib/lono/jade.rb', line 105

def finder
  "Lono::Finder::#{@type.camelize}".constantize.new
end

#materializeObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/lono/jade.rb', line 48

def materialize
  @jadespec = finder.find(@name)
  download unless @jadespec
  # Pretty tricky. Flush memoized finder(true) since download changes filesystem. Not memoizing at all is 2x slower
  @jadespec = finder(true).find(@name)
  return nil unless @jadespec
  if @jadespec.source_type == "materialized"
    # possible "duplicated" jade instances with same name but will uniq in final materialized Gemfile
    case @jadespec.lono_type
    when "configset"
      Lono::Jade::Registry.downloaded_configsets << self
    when "extension"
      Lono::Jade::Registry.downloaded_extensions << self
    end
  end
  evaluate_meta_rb
  @jadespec
end

#repoObject



19
20
21
# File 'lib/lono/jade.rb', line 19

def repo
  @registry.options[:repo] || @name
end

#resolved!Object



97
98
99
# File 'lib/lono/jade.rb', line 97

def resolved!
  @resolved = true
end

#resolved?Boolean

Returns:

  • (Boolean)


101
102
103
# File 'lib/lono/jade.rb', line 101

def resolved?
  @resolved
end

#resource_from_parentObject



38
39
40
41
42
43
44
45
46
# File 'lib/lono/jade.rb', line 38

def resource_from_parent
  parent = registry.parent # using local variable intentionally
  resource = nil
  while parent # go all the way to the highest parent
    resource = parent.registry.resource
    parent = parent.registry.parent
  end
  resource
end

#rootObject

root is kind of special. root is needed for materialization but can accidentally get called too early before materialization. So treat it specially with an error.



25
26
27
28
# File 'lib/lono/jade.rb', line 25

def root
  raise "ERROR: root is not available until jade has been materialized" unless @jadespec
  @jadespec.root
end