Class: LtiTemplateBuilder::Builder
- Inherits:
-
Object
- Object
- LtiTemplateBuilder::Builder
- Defined in:
- lib/lti_template_builder/builder.rb
Instance Attribute Summary collapse
-
#after_bundle_commands ⇒ Object
Returns the value of attribute after_bundle_commands.
-
#gem_dependencies ⇒ Object
Returns the value of attribute gem_dependencies.
-
#gem_dev_dependencies ⇒ Object
Returns the value of attribute gem_dev_dependencies.
-
#recipes ⇒ Object
Returns the value of attribute recipes.
Instance Method Summary collapse
- #add(name, args = {}) ⇒ Object
- #add_gem_recipe ⇒ Object
-
#initialize ⇒ Builder
constructor
A new instance of Builder.
- #render_to_screen ⇒ Object
- #save_to_file(path) ⇒ Object
- #to_script ⇒ Object
Constructor Details
#initialize ⇒ Builder
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_commands ⇒ Object
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_dependencies ⇒ Object
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_dependencies ⇒ Object
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 |
#recipes ⇒ Object
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_recipe ⇒ Object
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_screen ⇒ Object
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_script ⇒ Object
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 |