Module: Ardb::RecordSpy::ClassMethods
- Defined in:
- lib/ardb/record_spy.rb
Defined Under Namespace
Classes: CallbackType
Instance Attribute Summary collapse
- #relation_spy ⇒ Object
-
#table_name ⇒ Object
Returns the value of attribute table_name.
Instance Method Summary collapse
- #arel_table ⇒ Object
-
#associations ⇒ Object
Associations.
- #callbacks ⇒ Object
- #custom_callback_types ⇒ Object
- #define_model_callbacks(*args) ⇒ Object
- #scoped ⇒ Object
- #validate(method_name = nil, &block) ⇒ Object
- #validates_associated(*args) ⇒ Object
- #validates_each(*args, &block) ⇒ Object
- #validates_with(*args) ⇒ Object
-
#validations ⇒ Object
Validations.
Instance Attribute Details
#relation_spy ⇒ Object
145 146 147 |
# File 'lib/ardb/record_spy.rb', line 145 def relation_spy @relation_spy ||= RelationSpy.new end |
#table_name ⇒ Object
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_table ⇒ Object
149 150 151 |
# File 'lib/ardb/record_spy.rb', line 149 def arel_table @arel_table ||= Arel::Table.new(self.table_name) end |
#associations ⇒ Object
Associations
28 29 30 |
# File 'lib/ardb/record_spy.rb', line 28 def associations @associations ||= [] end |
#callbacks ⇒ Object
88 89 90 |
# File 'lib/ardb/record_spy.rb', line 88 def callbacks @callbacks ||= [] end |
#custom_callback_types ⇒ Object
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) = args.last.kind_of?(Hash) ? args.pop : {} types = [:only] || [:before, :around, :after] = class << self; self; end args.each do |name| self.custom_callback_types << CallbackType.new(name, ) types.each do |type| method_name = "#{type}_#{name}" .send(:define_method, method_name) do |*args, &block| self.callbacks << Callback.new(method_name, *args, &block) end end end end |
#scoped ⇒ Object
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 |
#validations ⇒ Object
Validations
49 50 51 |
# File 'lib/ardb/record_spy.rb', line 49 def validations @validations ||= [] end |