Class: LtiTemplateBuilder::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/lti_template_builder/builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBuilder

Returns a new instance of Builder.



5
6
7
8
9
10
# File 'lib/lti_template_builder/builder.rb', line 5

def initialize
  @gem_dependencies = []
  @gem_dev_dependencies = []
  @after_bundle_commands = []
  @recipes = []
end

Instance Attribute Details

#after_bundle_commandsObject

Returns the value of attribute after_bundle_commands.



3
4
5
# File 'lib/lti_template_builder/builder.rb', line 3

def after_bundle_commands
  @after_bundle_commands
end

#gem_dependenciesObject

Returns the value of attribute gem_dependencies.



3
4
5
# File 'lib/lti_template_builder/builder.rb', line 3

def gem_dependencies
  @gem_dependencies
end

#gem_dev_dependenciesObject

Returns the value of attribute gem_dev_dependencies.



3
4
5
# File 'lib/lti_template_builder/builder.rb', line 3

def gem_dev_dependencies
  @gem_dev_dependencies
end

#recipesObject

Returns the value of attribute recipes.



3
4
5
# File 'lib/lti_template_builder/builder.rb', line 3

def recipes
  @recipes
end

Instance Method Details

#add(name, args = {}) ⇒ Object



22
23
24
25
26
27
28
29
30
31
# File 'lib/lti_template_builder/builder.rb', line 22

def add(name, args={})
  klass_name = "LtiTemplateBuilder::#{name.to_s.classify}"
  recipe_klass = klass_name.constantize
  recipe = recipe_klass.new
  recipe.setup(args)
  recipe.gem_dependencies.each { |dep| @gem_dependencies << dep }
  recipe.gem_dev_dependencies.each { |dep| @gem_dev_dependencies << dep }
  recipe.after_bundle_commands.each { |cmd| @after_bundle_commands << cmd }
  @recipes << { name: name.to_sym, recipe: recipe.render }
end

#add_gem_recipeObject



12
13
14
15
16
17
18
19
20
# File 'lib/lti_template_builder/builder.rb', line 12

def add_gem_recipe
  recipe = LtiTemplateBuilder::Gems.new
  recipe.setup({
    gem_dependencies: @gem_dependencies.uniq,
    gem_dev_dependencies: @gem_dev_dependencies.uniq,
    after_bundle_commands: @after_bundle_commands.uniq
  })
  @recipes.unshift({ name: :gems, recipe: recipe.render })
end

#render_to_screenObject



43
44
45
# File 'lib/lti_template_builder/builder.rb', line 43

def render_to_screen
  puts self.to_script
end

#save_to_file(path) ⇒ Object



47
48
49
# File 'lib/lti_template_builder/builder.rb', line 47

def save_to_file(path)
  File.open(path, "w") { |file| file.write(self.to_script) }
end

#to_scriptObject



33
34
35
36
37
38
39
40
41
# File 'lib/lti_template_builder/builder.rb', line 33

def to_script
  add_gem_recipe
  ret = []
  @recipes.each do |item|
    ret << "\n# ---------------------------- Recipe: #{item[:name]} ---------------------------\n\n"
    ret << item[:recipe]
  end
  ret.join("\n\n")
end