Module: Ansr::Model::ClassMethods

Defined in:
lib/ansr/model.rb

Defined Under Namespace

Classes: TypeProxy

Instance Method Summary collapse

Instance Method Details

#build_default_scopeObject



47
48
49
# File 'lib/ansr/model.rb', line 47

def build_default_scope
   Ansr::Relation.new(model(), table())
end

#column_typesObject



51
52
53
# File 'lib/ansr/model.rb', line 51

def column_types
  TypeProxy.new(table())
end

#engineObject



39
40
41
# File 'lib/ansr/model.rb', line 39

def engine
  model()
end

#inherited(subclass) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/ansr/model.rb', line 10

def inherited(subclass)
  super
  # a hack for sanitize sql overrides to work, and some others where @klass used in place of klass()
  subclass.instance_variable_set("@klass", subclass)
  # a hack for the intermediate abstract model classes to work with table_name
  subclass.instance_variable_set("@table_name", subclass.name)
end

#modelObject



18
19
20
21
22
23
24
# File 'lib/ansr/model.rb', line 18

def model
  m = begin
    instance_variable_get "@klass"
  end
  raise "#{name()}.model() -> nil" unless m
  m
end

#referencesObject



26
27
28
# File 'lib/ansr/model.rb', line 26

def references
  []
end

#spawnObject



5
6
7
8
# File 'lib/ansr/model.rb', line 5

def spawn
  s = build_default_scope
  s.references!(references())
end

#tableObject



30
31
32
33
34
35
36
37
# File 'lib/ansr/model.rb', line 30

def table
  type = (config[:table_class] || Ansr::Arel::BigTable)
  if @table
    # allow the table class to be reconfigured
    @table = nil unless @table.class == type
  end
  @table ||= type.new(self)
end