Class: Prick::Build::FoxBatch

Inherits:
BuildBatch show all
Defined in:
lib/prick/builder/batch.rb

Instance Attribute Summary

Attributes inherited from BuildBatch

#builder, #nodes

Instance Method Summary collapse

Methods inherited from BuildBatch

#dump, #initialize, #kind

Methods included from Timer

file, file=, new, off!, off?, on!, on?, scale, scale=, #time, time, unit, unit=

Constructor Details

This class inherits a constructor from Prick::Build::BuildBatch

Instance Method Details

#executeObject

Inlining Fox instead of using command line program as it saves some deciseconds



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# File 'lib/prick/builder/batch.rb', line 106

def execute
  t_type = t_fox = t_exe = nil

  super {
    timer = Timer.new "Execute fox batch (nodes: #{nodes.size}, clean: #{builder.clean})"
    t_type = Timer.new "  Load data model"

    files = nodes.map(&:path)

    # Load meta object
    meta = PgMeta.new(conn, exclude_schemas: builder.pg_graph_ignore_schemas)

    # Create type object
    type = PgGraph::Type.new(meta, builder.reflections_file)

    # Timer
    t_type.stop
    t_fox = Timer.new "  Parse files"

    # Fetch state
    ids, anchors = FixtureFox::Fox.read_state(type, Prick.state.fox_state_file)

    # Create fox object
    #
    fox = FixtureFox::Fox.new(type, ids: ids, anchors: anchors)

    # Parse files
    for file in files
      source, lines = fox.tokenize(file)
      fox.parse(source, lines)
    end

    # Analyze
    fox.assign_types
    fox.generate

    # Dump new state file
    fox.write_state(Prick.state.fox_state_file)

    # Timer
    t_fox.stop
    t_exe = Timer.new "  Execute SQL"

    delete = builder.clean ? :none : :touched
    begin
      conn.execute fox.to_sql(format: :exec, delete: delete)
    rescue PG::SyntaxError, PG::Error => ex
      raise PostgresError.new(ex.message)
    end
  }
  t_type.emit
  t_fox.emit
  t_exe.emit
end