Class: Hekenga::Scaffold
- Inherits:
-
Object
- Object
- Hekenga::Scaffold
- Defined in:
- lib/hekenga/scaffold.rb
Instance Method Summary collapse
-
#initialize(description) ⇒ Scaffold
constructor
A new instance of Scaffold.
- #to_path ⇒ Object
- #to_s ⇒ Object
- #write! ⇒ Object
Constructor Details
#initialize(description) ⇒ Scaffold
4 5 6 7 8 9 |
# File 'lib/hekenga/scaffold.rb', line 4 def initialize(description) @migration = Hekenga::Migration.new.tap do |migration| migration.description = description migration.stamp = Time.now end end |
Instance Method Details
#to_path ⇒ Object
18 19 20 21 |
# File 'lib/hekenga/scaffold.rb', line 18 def to_path @path ||= File.join(Hekenga.config.abs_dir, @migration.to_key.gsub(/\:/, '-') + '.rb') end |
#to_s ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/hekenga/scaffold.rb', line 23 def to_s " Hekenga.migration do\n ## Required\n description \#{@migration.description.inspect}\n created \#{@migration.timestamp.sub(\"T\", \" \").inspect}\n\n ## Optional\n #batch_size 25\n\n ## Simple tasks\n #task \"task description\" do\n # up do\n # end\n #end\n\n ## Per document tasks\n #per_document \"task description\" do\n # ## Required\n # scope MyModel.all\n #\n # ## Optional config\n # #parallel!\n # #timeless!\n # #always_write!\n # #skip_prepare!\n # #batch_size 25\n # #write_strategy :update # :delete_then_insert\n #\n # # Called once per batch, instance variables will be accessible\n # # in the filter, up and after blocks\n # #setup do |docs|\n # #end\n #\n # #filter do |doc|\n # #end\n #\n # up do |doc|\n # end\n #\n # # Called once per batch passing successfully written records\n # #after do |docs|\n # #end\n #end\n end\n EOF\nend\n".strip_heredoc |
#write! ⇒ Object
11 12 13 14 15 16 |
# File 'lib/hekenga/scaffold.rb', line 11 def write! if File.exist?(to_path) raise "That migration already exists!" end File.open(to_path, "w") {|f| f.puts self } end |