Class: Model
Direct Known Subclasses
Abuse, Annotation, Branch, Broadcast, Build, Commit, Cron, Email, Invoice, Job, Log, Membership, Message, Organization, OwnerGroup, Permission, PullRequest, QueueableJob, Repository, Request, SslKey, Stage, Star, Subscription, Tag, Token, Trial, TrialAllowance, User, UserBetaFeature
Class Method Summary
collapse
Instance Method Summary
collapse
default_dependencies_symbols_to_nullify, #default_dependencies_symbols_to_nullify, #default_dependencies_to_nullify, #nullify_all_dependencies, #nullify_default_dependencies, #nullify_dependencies
#ids_of_all_dependencies, #ids_of_all_dependencies_with_filtered, #ids_of_all_dependencies_without_reflection
#dependency_tree
#ids_of_all_direct_dependencies
#symbols_of_all_direct_dependencies
#ids_of_all_dependencies_nested
Class Method Details
.get_model(name) ⇒ Object
43
44
45
|
# File 'lib/model.rb', line 43
def self.get_model(name)
self.subclasses.find{ |m| m.name == name.to_s.camelcase }
end
|
.get_model_by_table_name(name) ⇒ Object
47
48
49
|
# File 'lib/model.rb', line 47
def self.get_model_by_table_name(name)
self.subclasses.find{ |m| m.table_name == name.to_s }
end
|
.ids_of_subclasses_entries ⇒ Object
51
52
53
54
55
|
# File 'lib/model.rb', line 51
def self.ids_of_subclasses_entries
self.subclasses.map do |subclass|
[subclass.name, subclass.all.map(&:id)] if subclass.any?
end.compact.to_h
end
|
.sum_of_subclasses_rows(except: []) ⇒ Object
57
58
59
60
61
62
63
|
# File 'lib/model.rb', line 57
def self.sum_of_subclasses_rows(except: [])
self.subclasses.map do |subclass|
next 0 if except.include?(subclass.table_name) || except.include?(subclass.name)
subclass.all.size
end.reduce(:+)
end
|
Instance Method Details
#associations ⇒ Object
32
33
34
35
36
37
|
# File 'lib/model.rb', line 32
def associations
self.class.reflect_on_all_associations.map do |association|
value = self.send(association.name)
AssociationWithValue.new(association, value)
end
end
|
#associations_hash ⇒ Object
26
27
28
29
30
|
# File 'lib/model.rb', line 26
def associations_hash
self.associations.map do |association|
[association.name, association]
end.to_h
end
|
#associations_without_belongs_to ⇒ Object
39
40
41
|
# File 'lib/model.rb', line 39
def associations_without_belongs_to
self.associations.select { |a| a.macro != :belongs_to }
end
|
#attributes_without_id ⇒ Object
22
23
24
|
# File 'lib/model.rb', line 22
def attributes_without_id
self.attributes.reject{|k, v| k == "id"}
end
|
#removed? ⇒ Boolean
65
66
67
68
69
70
71
72
|
# File 'lib/model.rb', line 65
def removed?
begin
reload
false
rescue ActiveRecord::RecordNotFound => e
true
end
end
|