Class: Lono::Finder::Base
- Inherits:
-
Object
- Object
- Lono::Finder::Base
show all
- Extended by:
- Memoist
- Defined in:
- lib/lono/finder/base.rb
Class Method Summary
collapse
Instance Method Summary
collapse
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
143
144
145
|
# File 'lib/lono/finder/base.rb', line 143
def find(name)
new.find(name)
end
|
.list(options = {}) ⇒ Object
147
148
149
|
# File 'lib/lono/finder/base.rb', line 147
def list(options={})
new.list(options)
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",
},...]
59
60
61
62
63
64
65
66
67
|
# File 'lib/lono/finder/base.rb', line 59
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
70
71
72
73
|
# File 'lib/lono/finder/base.rb', line 70
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
41
42
43
|
# File 'lib/lono/finder/base.rb', line 41
def gems
components(gem_roots, "gem")
end
|
#list(options = {}) ⇒ Object
Used for blueprints, configsets, and blueprint/configsets
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
# File 'lib/lono/finder/base.rb', line 76
def list(options={})
table = Text::Table.new
table.head = ["Name", "Path", "Type"]
components = find_all.sort_by { |jadespec| jadespec.name }
components.each do |jadespec|
pretty_path = jadespec.root.sub("#{Lono.root}/", "").sub(ENV['HOME'], "~")
unless options[: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(options[:message] || "Available #{type.pluralize}:")
puts table
end
end
|
#local ⇒ Object
27
28
29
|
# File 'lib/lono/finder/base.rb', line 27
def local
project + vendor + gems
end
|
#materialized ⇒ Object
Folders that each materialized gems to tmp/jades
46
47
48
|
# File 'lib/lono/finder/base.rb', line 46
def materialized
components(materialized_gem_roots, "materialized")
end
|
#project ⇒ Object
31
32
33
34
|
# File 'lib/lono/finder/base.rb', line 31
def project
roots = path_roots("#{@lono_root}/app/#{type.pluralize}")
components(roots, "project")
end
|
#vendor ⇒ Object
36
37
38
39
|
# File 'lib/lono/finder/base.rb', line 36
def vendor
roots = path_roots("#{@lono_root}/vendor/#{type.pluralize}")
components(roots, "vendor")
end
|