Class: Lono::Configset::Strategy::Base

Inherits:
Object
  • Object
show all
Extended by:
Memoist
Includes:
EvaluateFile
Defined in:
lib/lono/configset/strategy/base.rb

Direct Known Subclasses

Dsl, Erb

Instance Method Summary collapse

Methods included from EvaluateFile

#evaluate_file

Constructor Details

#initialize(options = {}) ⇒ Base

Returns a new instance of Base.



16
17
18
19
20
21
22
# File 'lib/lono/configset/strategy/base.rb', line 16

def initialize(options={})
  @options = options
  @configset = options[:configset]
  @root = options[:root]
  @resource = options[:resource] || "FakeResource"
  @blueprint = Lono::Conventions.new(options).blueprint
end

Instance Method Details

#buildObject



24
25
26
27
28
29
# File 'lib/lono/configset/strategy/base.rb', line 24

def build
  @evaluation_path = find_evaluation_path # implemented by subclass
  copy_instance_variables
  load_configset_helpers
  load # implemented by subclass
end

#copy_instance_variablesObject



32
33
34
35
# File 'lib/lono/configset/strategy/base.rb', line 32

def copy_instance_variables
  load_blueprint_predefined_variables
  load_project_predefined_variables
end

#load_blueprint_predefined_variablesObject



37
38
39
# File 'lib/lono/configset/strategy/base.rb', line 37

def load_blueprint_predefined_variables
  evaluate_file("#{@root}/lib/variables.rb")
end

#load_configset_helpersObject



51
52
53
54
55
56
57
58
59
60
61
# File 'lib/lono/configset/strategy/base.rb', line 51

def load_configset_helpers
  paths = Dir.glob("#{@root}/lib/helpers/**/*.rb")
  paths.sort_by! { |p| p.size } # load possible namespaces first
  paths.each do |path|
    filename = path.sub(%r{.*/lib/helpers/},'').sub('.rb','')
    module_name = filename.camelize

    require path
    self.class.send :include, module_name.constantize
  end
end

#load_project_predefined_variablesObject



41
42
43
44
45
46
47
48
49
# File 'lib/lono/configset/strategy/base.rb', line 41

def load_project_predefined_variables
  paths = [
    "#{Lono.root}/configs/#{@blueprint}/configsets/variables.rb", # global
    "#{Lono.root}/configs/#{@blueprint}/configsets/#{@configset}/variables.rb", # configset specific
  ]
  paths.each do |path|
    evaluate_file(path)
  end
end