Class: Lono::Finder::Base

Inherits:
Object
  • Object
show all
Extended by:
Memoist
Defined in:
lib/lono/finder/base.rb

Direct Known Subclasses

Blueprint, Configset

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



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(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",
},...]


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

Returns:

  • (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

#gemsObject



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(options={})
  table = Text::Table.new
  table.head = ["Name", "Path", "Type"]

  components = find_all
  components.each do |jadespec|
    pretty_path = jadespec.root.sub("#{Lono.root}/", "")
    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

#localObject

overridden in finder/blueprint/configset.rb



28
29
30
# File 'lib/lono/finder/base.rb', line 28

def local
  project + vendor + gems
end

#materializedObject

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

#projectObject



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

#vendorObject



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