Class: Hekenga::Scaffold

Inherits:
Object
  • Object
show all
Defined in:
lib/hekenga/scaffold.rb

Instance Method Summary collapse

Constructor Details

#initialize(description) ⇒ Scaffold

Returns a new instance of 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_pathObject



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_sObject



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
70
# File 'lib/hekenga/scaffold.rb', line 23

def to_s
  <<-EOF.strip_heredoc
  Hekenga.migration do
    ## Required
    description #{@migration.description.inspect}
    created #{@migration.timestamp.sub("T", " ").inspect}

    ## Optional
    #batch_size 25

    ## Simple tasks
    #task "task description" do
    #  up do
    #  end
    #end

    ## Per document tasks
    #per_document "task description" do
    #  ## Required
    #  scope MyModel.all
    #
    #  ## Optional config
    #  #parallel!
    #  #timeless!
    #  #always_write!
    #  #skip_prepare!
    #  #batch_size 25
    #  #write_strategy :update # :delete_then_insert
    #  #cursor_timeout 86_400 # max allowed time for the cursor to survive, in seconds
    #
    #  # Called once per batch, instance variables will be accessible
    #  # in the filter, up and after blocks
    #  #setup do |docs|
    #  #end
    #
    #  #filter do |doc|
    #  #end
    #
    #  up do |doc|
    #  end
    #
    #  # Called once per batch passing successfully written records
    #  #after do |docs|
    #  #end
    #end
  end
  EOF
end

#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