Class: Ramix::Builder
Overview
Ramix::Builder be responsible for adding some useful methods on the top or the bottom of template.
Instance Method Summary collapse
- #import(template, *args) ⇒ Object
-
#initialize(default_template_path = nil, &block) ⇒ Builder
constructor
A new instance of Builder.
-
#run ⇒ Object
Write some useful methods and the content of recipe in the file.
Methods included from Helpers
#before_callbacks, #callback_functions, #callbacks, #preparation_methods, #rails_version
Constructor Details
#initialize(default_template_path = nil, &block) ⇒ Builder
Returns a new instance of Builder.
8 9 10 11 12 |
# File 'lib/ramix/builder.rb', line 8 def initialize(default_template_path = nil, &block) @template_path = default_template_path || tempfile_path @import = [] instance_eval(&block) if block_given? end |
Instance Method Details
#import(template, *args) ⇒ Object
14 15 16 |
# File 'lib/ramix/builder.rb', line 14 def import(template, *args) @import << [template.order, proc { template.output(*args) }] end |
#run ⇒ Object
Write some useful methods and the content of recipe in the file. Return the path of the template.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/ramix/builder.rb', line 20 def run begin File.open(@template_path, "a+") do |file| file.write preparation_methods file.write rails_version file.write callback_functions ordered_templates.each{ |template| file.write template[1].call } file.write before_callbacks file.write callbacks end rescue Exception => e puts "Create template #{@template} error~~ #{e.}" end @template_path end |