class Lono::Finder::Base
Public Class Methods
find(name)
click to toggle source
# File lib/lono/finder/base.rb, line 143 def find(name) new.find(name) end
list(options={})
click to toggle source
# File lib/lono/finder/base.rb, line 147 def list(options={}) new.list(options) end
new(lono_root: nil, blueprint_root: nil)
click to toggle source
# 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
Public Instance Methods
components(roots, source_type)
click to toggle source
Components: blueprints or configsets Returns array of config Hashes. Example structure:
[{ name: "cfn-hup", root: "/path/to/gem/root", source_type: "project", },...]
# 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)
click to toggle source
# 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)
click to toggle source
Returns root path of component: blueprint or configset
# 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)
click to toggle source
# File lib/lono/finder/base.rb, line 19 def find_all(local_only: false) if local_only local else local + materialized end end
gems()
click to toggle source
# File lib/lono/finder/base.rb, line 41 def gems components(gem_roots, "gem") end
list(options={})
click to toggle source
Used for blueprints, configsets, and blueprint/configsets
# 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()
click to toggle source
# File lib/lono/finder/base.rb, line 27 def local project + vendor + gems end
materialized()
click to toggle source
Folders that each materialized gems to tmp/jades
# File lib/lono/finder/base.rb, line 46 def materialized components(materialized_gem_roots, "materialized") end
project()
click to toggle source
# File lib/lono/finder/base.rb, line 31 def project roots = path_roots("#{@lono_root}/app/#{type.pluralize}") components(roots, "project") end
vendor()
click to toggle source
# File lib/lono/finder/base.rb, line 36 def vendor roots = path_roots("#{@lono_root}/vendor/#{type.pluralize}") components(roots, "vendor") end
Private Instance Methods
gem_roots()
click to toggle source
Example return:
[ "/home/ec2-user/.rbenv/versions/2.5.6/lib/ruby/gems/2.5.0/gems/rake-13.0.1", "/home/ec2-user/.rbenv/versions/2.5.6/lib/ruby/gems/2.5.0/gems/thor-0.20.3" ]
# File lib/lono/finder/base.rb, line 108 def gem_roots Bundler.load.specs.map do |spec| spec.full_gem_path end end
materialized_gem_roots()
click to toggle source
# File lib/lono/finder/base.rb, line 115 def materialized_gem_roots gemfile_lock = "#{Lono.root}/tmp/jades/Gemfile.lock" return [] unless File.exist?(gemfile_lock) parser = Bundler::LockfileParser.new(Bundler.read_file(gemfile_lock)) specs = parser.specs # __materialize__ only exists in Gem::LazySpecification and not in Gem::Specification specs.each { |spec| spec.__materialize__ } begin specs.map do |spec| spec.full_gem_path end rescue RuntimeError => e if e.message.include?("LazySpecification has not been materialized yet") # Thinking quiet behavior is preferred. Leaving comment here for now. # puts "WARN: The Finder class is having trouble using the cached tmp/jades/Gemfile.lock to search for materialized gems." # puts "This can happen when materialized gems are updated. It is generally safe to ignore." # puts "To remove this warning you can remove the cached Gemfile.lock" return [] else raise(e) end end end
path_roots(path)
click to toggle source
# File lib/lono/finder/base.rb, line 97 def path_roots(path) Dir.glob("#{path}/*").to_a end