Module: Ardb::RecordSpy::ClassMethods

Defined in:
lib/ardb/record_spy.rb

Defined Under Namespace

Classes: CallbackType

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#relation_spyObject



145
146
147
# File 'lib/ardb/record_spy.rb', line 145

def relation_spy
  @relation_spy ||= RelationSpy.new
end

#table_nameObject

Returns the value of attribute table_name.



24
25
26
# File 'lib/ardb/record_spy.rb', line 24

def table_name
  @table_name
end

Instance Method Details

#arel_tableObject



149
150
151
# File 'lib/ardb/record_spy.rb', line 149

def arel_table
  @arel_table ||= Arel::Table.new(self.table_name)
end

#associationsObject

Associations



28
29
30
# File 'lib/ardb/record_spy.rb', line 28

def associations
  @associations ||= []
end

#callbacksObject



88
89
90
# File 'lib/ardb/record_spy.rb', line 88

def callbacks
  @callbacks ||= []
end

#custom_callback_typesObject



120
121
122
# File 'lib/ardb/record_spy.rb', line 120

def custom_callback_types
  @custom_callback_types ||= []
end

#define_model_callbacks(*args) ⇒ Object



124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/ardb/record_spy.rb', line 124

def define_model_callbacks(*args)
  options   = args.last.kind_of?(Hash) ? args.pop : {}
  types     = options[:only] || [:before, :around, :after]
  metaclass = class << self; self; end

  args.each do |name|
    self.custom_callback_types << CallbackType.new(name, options)
    types.each do |type|
      method_name = "#{type}_#{name}"
      metaclass.send(:define_method, method_name) do |*args, &block|
        self.callbacks << Callback.new(method_name, *args, &block)
      end
    end
  end
end

#scopedObject



153
154
155
# File 'lib/ardb/record_spy.rb', line 153

def scoped
  self.relation_spy
end

#validate(method_name = nil, &block) ⇒ Object



84
85
86
# File 'lib/ardb/record_spy.rb', line 84

def validate(method_name = nil, &block)
  self.validations << Validation.new(:custom, method_name, &block)
end

#validates_associated(*args) ⇒ Object



72
73
74
# File 'lib/ardb/record_spy.rb', line 72

def validates_associated(*args)
  self.validations << Validation.new(:associated, *args)
end

#validates_each(*args, &block) ⇒ Object



80
81
82
# File 'lib/ardb/record_spy.rb', line 80

def validates_each(*args, &block)
  self.validations << Validation.new(:each, *args, &block)
end

#validates_with(*args) ⇒ Object



76
77
78
# File 'lib/ardb/record_spy.rb', line 76

def validates_with(*args)
  self.validations << Validation.new(:with, *args)
end

#validationsObject

Validations



49
50
51
# File 'lib/ardb/record_spy.rb', line 49

def validations
  @validations ||= []
end