Class: DataShift::ModelMethods::Manager

Inherits:
Object
  • Object
show all
Defined in:
lib/datashift/model_methods/model_methods_manager.rb

Class Method Summary collapse

Class Method Details

.catalog_class(klass, options = {}) ⇒ Object

:reload => clear caches and re-perform lookup

:instance_methods => if true include instance method type 'setters' as well as model's pure columns


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
# File 'lib/datashift/model_methods/model_methods_manager.rb', line 39

def self.catalog_class( klass, options = {} )

  return collections[klass] if collections[klass] && !options[:reload]

  ModelMethods::Catalogue.populate(klass, options) unless ModelMethods::Catalogue.catalogued?(klass)

  collection = ModelMethods::Collection.new( klass )

  DataShift::ModelMethods::Catalogue.assignments_for(klass).each do |n|
    collection << ModelMethod.new(klass, n, :assignment)
  end

  DataShift::ModelMethods::Catalogue.has_one_for(klass).each do |n|
    collection << ModelMethod.new(klass, n, :has_one)
  end

  DataShift::ModelMethods::Catalogue.has_many_for(klass).each do |n|
    collection << ModelMethod.new(klass, n, :has_many)
  end

  DataShift::ModelMethods::Catalogue.belongs_to_for(klass).each do |n|
    collection << ModelMethod.new(klass, n, :belongs_to)
  end

  collections[klass] = collection

  collection

end

.clearObject



69
70
71
# File 'lib/datashift/model_methods/model_methods_manager.rb', line 69

def self.clear
  collections.clear
end

.collectionsObject



15
16
17
# File 'lib/datashift/model_methods/model_methods_manager.rb', line 15

def self.collections
  @collections ||= {}
end

.for(klass) ⇒ Object



19
20
21
# File 'lib/datashift/model_methods/model_methods_manager.rb', line 19

def self.for(klass)
  collections[klass]
end

.for?(klass) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/datashift/model_methods/model_methods_manager.rb', line 23

def self.for?(klass)
  (collections[klass] != nil)
end