Module: InheritableSchema::ClassMethods

Defined in:
app/models/base_new.rb

Instance Method Summary collapse

Instance Method Details

#inheritable_schema(&blk) ⇒ Object



201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
# File 'app/models/base_new.rb', line 201

def inheritable_schema(&blk)
  if blk
    self.schema_builders << blk
  
    if @schema.nil?
      # set_dataset(:tablename) in set_schema() force to overwrite
      # dataset.row_proc to the standard one even if the
      # dataset.row_proc is set something another. This becomes problem when
      # another plugin needed to set its own row_proc.

      # This is workaround to prevent from above.
      row_proc = dataset.row_proc
      set_schema(implicit_table_name) do
        primary_key :id, :type=>Integer, :unsigned=>true
      end
      dataset.row_proc = row_proc if row_proc.is_a?(Proc)
    end

    builders = []
    c = self
    begin
      builders << c.schema_builders if c.respond_to?(:schema_builders)
    end while (c = c.superclass) < InheritableSchema

    builders = builders.reverse.flatten
    builders.delete(nil)
    builders.each { |blk|
      @schema.instance_eval(&blk)
    }
  end
end

#schema_buildersObject



197
198
199
# File 'app/models/base_new.rb', line 197

def schema_builders
  @schema_builders ||= []
end