Class: Lono::Finder::Base
- Inherits:
-
Object
- Object
- Lono::Finder::Base
- Extended by:
- Memoist
- Defined in:
- lib/lono/finder/base.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#components(roots, source_type) ⇒ Object
Components: blueprints or configsets Returns array of config Hashes.
- #detect?(root) ⇒ Boolean
-
#find(name, local_only: false) ⇒ Object
Returns root path of component: blueprint or configset.
- #find_all(local_only: false) ⇒ Object
- #gems ⇒ Object
-
#initialize(lono_root: nil, blueprint_root: nil) ⇒ Base
constructor
A new instance of Base.
-
#list(options = {}) ⇒ Object
Used for blueprints, configsets, and blueprint/configsets.
-
#local ⇒ Object
overridden in finder/blueprint/configset.rb.
-
#materialized ⇒ Object
Folders that each materialized gems to tmp/configsets.
- #project ⇒ Object
- #vendor ⇒ Object
Constructor Details
#initialize(lono_root: nil, blueprint_root: nil) ⇒ Base
Returns a new instance of Base.
8 9 10 11 |
# File 'lib/lono/finder/base.rb', line 8 def initialize(lono_root: nil, blueprint_root: nil) @lono_root = lono_root || Lono.root @blueprint_root = blueprint_root || Lono.blueprint_root end |
Class Method Details
.find(name) ⇒ Object
131 132 133 |
# File 'lib/lono/finder/base.rb', line 131 def find(name) new.find(name) end |
.list(options = {}) ⇒ Object
135 136 137 |
# File 'lib/lono/finder/base.rb', line 135 def list(={}) new.list() end |
Instance Method Details
#components(roots, source_type) ⇒ Object
Components: blueprints or configsets Returns array of config Hashes. Example structure:
[{
name: "cfn-hup",
root: "/path/to/gem/root",
source_type: "project",
},...]
60 61 62 63 64 65 66 67 68 |
# File 'lib/lono/finder/base.rb', line 60 def components(roots, source_type) components = [] roots.each do |root| next unless detect?(root) jadespec = Lono::Jadespec.new(root, source_type) components << jadespec end components end |
#detect?(root) ⇒ Boolean
71 72 73 74 |
# File 'lib/lono/finder/base.rb', line 71 def detect?(root) expr = "#{root}/#{detection_path}" Dir.glob(expr).size > 0 end |
#find(name, local_only: false) ⇒ Object
Returns root path of component: blueprint or configset
14 15 16 17 |
# File 'lib/lono/finder/base.rb', line 14 def find(name, local_only: false) all = find_all(local_only: local_only) all.find { |jadespec| jadespec.name == name } end |
#find_all(local_only: false) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/lono/finder/base.rb', line 19 def find_all(local_only: false) if local_only local else local + materialized end end |
#gems ⇒ Object
42 43 44 |
# File 'lib/lono/finder/base.rb', line 42 def gems components(gem_roots, "gem") end |
#list(options = {}) ⇒ Object
Used for blueprints, configsets, and blueprint/configsets
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/lono/finder/base.rb', line 77 def list(={}) table = Text::Table.new table.head = ["Name", "Path", "Type"] components = find_all components.each do |jadespec| pretty_path = jadespec.root.sub("#{Lono.root}/", "") unless [:filter_materialized] && jadespec.source_type == "materialized" table.rows << [jadespec.name, pretty_path, jadespec.source_type] end end if table.rows.empty? puts "No #{type.pluralize} found." else puts([:message] || "Available #{type.pluralize}:") puts table end end |
#local ⇒ Object
overridden in finder/blueprint/configset.rb
28 29 30 |
# File 'lib/lono/finder/base.rb', line 28 def local project + vendor + gems end |
#materialized ⇒ Object
Folders that each materialized gems to tmp/configsets
47 48 49 |
# File 'lib/lono/finder/base.rb', line 47 def materialized components(materialized_gem_roots, "materialized") end |
#project ⇒ Object
32 33 34 35 |
# File 'lib/lono/finder/base.rb', line 32 def project roots = path_roots("#{@lono_root}/app/#{type.pluralize}") components(roots, "project") end |
#vendor ⇒ Object
37 38 39 40 |
# File 'lib/lono/finder/base.rb', line 37 def vendor roots = path_roots("#{@lono_root}/vendor/#{type.pluralize}") components(roots, "vendor") end |