Class: Lono::Jade

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

Defined Under Namespace

Modules: Circular

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.



14
15
16
17
18
19
20
21
22
# File 'lib/lono/jade.rb', line 14

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 = []
  self.class.tracked << self
end

Instance Attribute Details

#dependenciesObject

Returns the value of attribute dependencies.



12
13
14
# File 'lib/lono/jade.rb', line 12

def dependencies
  @dependencies
end

#depends_onsObject

Returns the value of attribute depends_ons.



12
13
14
# File 'lib/lono/jade.rb', line 12

def depends_ons
  @depends_ons
end

#fromObject

Returns the value of attribute from.



12
13
14
# File 'lib/lono/jade.rb', line 12

def from
  @from
end

#jadespecObject (readonly)

Returns the value of attribute jadespec.



13
14
15
# File 'lib/lono/jade.rb', line 13

def jadespec
  @jadespec
end

#nameObject (readonly)

Returns the value of attribute name.



13
14
15
# File 'lib/lono/jade.rb', line 13

def name
  @name
end

#registryObject (readonly)

Returns the value of attribute registry.



13
14
15
# File 'lib/lono/jade.rb', line 13

def registry
  @registry
end

#typeObject (readonly)

Returns the value of attribute type.



13
14
15
# File 'lib/lono/jade.rb', line 13

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.



69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/lono/jade.rb', line 69

def download
  return if finder.find(@name, local_only: true) # no need to download because locally found
  # 4 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
  return unless %w[blueprint/configset configset].include?(@type) # TODO: support materializing nested blueprints later
  # only download jades that came from depends_on
  return unless @registry.parent || @type == "blueprint/configset"
  jade = Lono::Configset::Materializer::Jade.new(self)
  jade.build
end

#evaluate_meta_rbObject



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

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

#finderObject



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

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

#materializeObject



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

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
    self.class.downloaded << self
  end
  evaluate_meta_rb
  @jadespec
end

#repoObject



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

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

#resolved!Object



90
91
92
# File 'lib/lono/jade.rb', line 90

def resolved!
  @resolved = true
end

#resolved?Boolean

Returns:

  • (Boolean)


94
95
96
# File 'lib/lono/jade.rb', line 94

def resolved?
  @resolved
end

#resource_from_parentObject



41
42
43
44
45
46
47
48
49
# File 'lib/lono/jade.rb', line 41

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.



30
31
32
33
# File 'lib/lono/jade.rb', line 30

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