Class: DataShift::ModelMethods::Catalogue
- Inherits:
-
Object
- Object
- DataShift::ModelMethods::Catalogue
show all
- Extended by:
- Logging
- Includes:
- Logging
- Defined in:
- lib/datashift/model_methods/catalogue.rb
Overview
HIGH LEVEL COLLECTION METHODS
Class Method Summary
collapse
Methods included from Logging
logdir, logdir=, logger, verbose
Class Method Details
.assignments ⇒ Object
105
106
107
108
|
# File 'lib/datashift/model_methods/catalogue.rb', line 105
def self.assignments
@assignments ||= {}
@assignments
end
|
.assignments_for(klass) ⇒ Object
138
139
140
|
# File 'lib/datashift/model_methods/catalogue.rb', line 138
def self.assignments_for(klass)
assignments[klass] || []
end
|
.belongs_to ⇒ Object
rubocop:disable Style/PredicateName
90
91
92
93
|
# File 'lib/datashift/model_methods/catalogue.rb', line 90
def self.belongs_to
@belongs_to ||= {}
@belongs_to
end
|
.belongs_to_for(klass) ⇒ Object
126
127
128
|
# File 'lib/datashift/model_methods/catalogue.rb', line 126
def self.belongs_to_for(klass)
belongs_to[klass] || []
end
|
.catalogued?(klass) ⇒ Boolean
22
23
24
|
# File 'lib/datashift/model_methods/catalogue.rb', line 22
def self.catalogued?(klass)
catalogued.include?(klass)
end
|
79
80
81
82
83
84
85
86
|
# File 'lib/datashift/model_methods/catalogue.rb', line 79
def self.clear
belongs_to.clear
has_many.clear
assignments.clear
column_types.clear
has_one.clear
catalogued.clear
end
|
.column_names(klass) ⇒ Object
146
147
148
|
# File 'lib/datashift/model_methods/catalogue.rb', line 146
def self.column_names( klass )
Module.const_defined?(:Mongoid) ? klass.fields.keys : klass.column_names
end
|
.column_type_for(klass, column) ⇒ Object
142
143
144
|
# File 'lib/datashift/model_methods/catalogue.rb', line 142
def self.column_type_for(klass, column)
column_types[klass] ? column_types[klass][column] : []
end
|
.column_types ⇒ Object
121
122
123
124
|
# File 'lib/datashift/model_methods/catalogue.rb', line 121
def self.column_types
@column_types ||= {}
@column_types
end
|
95
96
97
98
|
# File 'lib/datashift/model_methods/catalogue.rb', line 95
def self.has_many
@has_many ||= {}
@has_many
end
|
.has_many_for(klass) ⇒ Object
130
131
132
|
# File 'lib/datashift/model_methods/catalogue.rb', line 130
def self.has_many_for(klass)
has_many[klass] || []
end
|
100
101
102
103
|
# File 'lib/datashift/model_methods/catalogue.rb', line 100
def self.has_one
@has_one ||= {}
@has_one
end
|
.has_one_for(klass) ⇒ Object
134
135
136
|
# File 'lib/datashift/model_methods/catalogue.rb', line 134
def self.has_one_for(klass)
has_one[klass] || []
end
|
.populate(klass, options = {}) ⇒ Object
Create simple picture of all the operator names for assignment available on a domain model, grouped by type of association (includes belongs_to and has_many which provides both << and = ) Options:
:reload => clear caches and re-perform lookup
:instance_methods => if true include instance method type 'setters' as well as model's pure columns
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
# File 'lib/datashift/model_methods/catalogue.rb', line 36
def self.populate(klass, options = {} )
raise "Cannot find operators supplied klass nil #{klass}" if klass.nil?
register(klass)
logger.debug("Catalogue - building operators information for #{klass}")
if options[:reload] || has_many[klass].nil?
if Module.const_defined?(:Mongoid)
has_many[klass] = klass.reflect_on_all_associations(:embeds_many).map { |i| i.name.to_s }
else
has_many[klass] = klass.reflect_on_all_associations(:has_many).map { |i| i.name.to_s }
klass.reflect_on_all_associations(:has_and_belongs_to_many).inject(has_many[klass]) do |x, i|
x << i.name.to_s
end
end
end
if options[:reload] || belongs_to[klass].nil?
belongs_to[klass] = klass.reflect_on_all_associations(:belongs_to).map { |i| i.name.to_s }
end
if options[:reload] || has_one[klass].nil?
if Module.const_defined?(:Mongoid)
has_one[klass] = klass.reflect_on_all_associations(:embeds_one).map { |i| i.name.to_s }
else
has_one[klass] = klass.reflect_on_all_associations(:has_one).map { |i| i.name.to_s }
end
end
if options[:reload] || assignments[klass].nil?
build_assignments( klass, options[:instance_methods] )
end
end
|
.setters(klass) ⇒ Object
N.B this return strings for consistency with other collections Removes methods that start with ‘_’
113
114
115
116
117
118
119
|
# File 'lib/datashift/model_methods/catalogue.rb', line 113
def self.setters( klass )
@keep_only_pure_setters ||= Regexp.new(/^[a-zA-Z]\w+=/)
setters = klass.instance_methods.grep(@keep_only_pure_setters).sort.collect( &:to_s )
setters.uniq
end
|
26
27
28
|
# File 'lib/datashift/model_methods/catalogue.rb', line 26
def self.size
catalogued.size
end
|