Class: Lono::Jade
- Inherits:
-
Object
- Object
- Lono::Jade
- 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
-
#dependencies ⇒ Object
Returns the value of attribute dependencies.
-
#depends_ons ⇒ Object
Returns the value of attribute depends_ons.
-
#from ⇒ Object
Returns the value of attribute from.
-
#jadespec ⇒ Object
readonly
Returns the value of attribute jadespec.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#registry ⇒ Object
readonly
Returns the value of attribute registry.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#download ⇒ Object
Must return config to set @jadespec in materialize Only allow download of Lono::Blueprint::Configset::Jade Other configsets should be configured in project Gemfile.
- #evaluate_meta_rb ⇒ Object
- #finder ⇒ Object
-
#initialize(name, type, registry = {}) ⇒ Jade
constructor
A new instance of Jade.
- #materialize ⇒ Object
- #repo ⇒ Object
- #resolved! ⇒ Object
- #resolved? ⇒ Boolean
- #resource_from_parent ⇒ Object
-
#root ⇒ Object
root is kind of special.
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
#dependencies ⇒ Object
Returns the value of attribute dependencies.
12 13 14 |
# File 'lib/lono/jade.rb', line 12 def dependencies @dependencies end |
#depends_ons ⇒ Object
Returns the value of attribute depends_ons.
12 13 14 |
# File 'lib/lono/jade.rb', line 12 def depends_ons @depends_ons end |
#from ⇒ Object
Returns the value of attribute from.
12 13 14 |
# File 'lib/lono/jade.rb', line 12 def from @from end |
#jadespec ⇒ Object (readonly)
Returns the value of attribute jadespec.
13 14 15 |
# File 'lib/lono/jade.rb', line 13 def jadespec @jadespec end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
13 14 15 |
# File 'lib/lono/jade.rb', line 13 def name @name end |
#registry ⇒ Object (readonly)
Returns the value of attribute registry.
13 14 15 |
# File 'lib/lono/jade.rb', line 13 def registry @registry end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
13 14 15 |
# File 'lib/lono/jade.rb', line 13 def type @type end |
Instance Method Details
#download ⇒ Object
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_rb ⇒ Object
84 85 86 87 88 |
# File 'lib/lono/jade.rb', line 84 def return unless %w[blueprint/configset configset].include?(@type) = Lono::Configset::Meta.new(self) .evaluate end |
#finder ⇒ Object
98 99 100 |
# File 'lib/lono/jade.rb', line 98 def finder "Lono::Finder::#{@type.camelize}".constantize.new end |
#materialize ⇒ Object
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 @jadespec end |
#repo ⇒ Object
24 25 26 |
# File 'lib/lono/jade.rb', line 24 def repo @registry.[:repo] || @name end |
#resolved! ⇒ Object
90 91 92 |
# File 'lib/lono/jade.rb', line 90 def resolved! @resolved = true end |
#resolved? ⇒ Boolean
94 95 96 |
# File 'lib/lono/jade.rb', line 94 def resolved? @resolved end |
#resource_from_parent ⇒ Object
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 |
#root ⇒ Object
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 |