Class: BetterRecord::Base
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.gender_enum(col) ⇒ Object
50
51
52
|
# File 'app/models/better_record/base.rb', line 50
def self.gender_enum(col)
enum col, BetterRecord::Gender::ENUM
end
|
.get_hashed_string(str) ⇒ Object
54
55
56
57
58
|
# File 'app/models/better_record/base.rb', line 54
def self.get_hashed_string(str)
ct = Time.now.to_i
cq = ActiveRecord::Base.sanitize_sql_array(["hash_password(?) as hashed_cert_#{t}", str])
select(cq).limit(1).first[:"hashed_cert_#{t}"]
end
|
.set_audit_methods! ⇒ Object
Class Methods ========================================================
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'app/models/better_record/base.rb', line 26
def self.set_audit_methods!
begin
t_name = BetterRecord::LoggedAction.table_name.sub('_view', '')
connection.execute(%Q(SELECT 1 FROM #{t_name}_#{self.table_name} LIMIT 1))
self.const_set(:LoggedAction, Class.new(ApplicationRecord))
self.const_get(:LoggedAction).table_name = "#{t_name}_#{self.table_name}"
self.const_get(:LoggedAction).primary_key = :event_id
rescue ActiveRecord::StatementInvalid
self.const_set(:LoggedAction, BetterRecord::LoggedAction)
end
self.has_many self.audit_relation_name,
class_name: "#{self.to_s}::LoggedAction",
primary_type: :table_name,
foreign_key: :row_id,
foreign_type: :table_name,
as: self.audit_relation_name
self
rescue ActiveRecord::NoDatabaseError
self
end
|
Instance Method Details
#dup(allow_full_dup = false) ⇒ Object
71
72
73
74
75
76
77
78
79
|
# File 'app/models/better_record/base.rb', line 71
def dup(allow_full_dup = false)
if !allow_full_dup && self.class.const_defined?(:NON_DUPABLE_KEYS)
super().tap do |r|
r.class::NON_DUPABLE_KEYS.each {|k| r[k] = nil }
end
else
super()
end
end
|
#get_hashed_string(str) ⇒ Object
Instance Methods =====================================================
63
64
65
|
# File 'app/models/better_record/base.rb', line 63
def get_hashed_string(str)
self.class.get_hashed_string(str)
end
|
#indifferent_attributes ⇒ Object
67
68
69
|
# File 'app/models/better_record/base.rb', line 67
def indifferent_attributes
attributes.with_indifferent_access
end
|