Class: ActiveRecord::ModelSpaces::ModelSpace
- Inherits:
-
Object
- Object
- ActiveRecord::ModelSpaces::ModelSpace
show all
- Includes:
- Util
- Defined in:
- lib/active_record/model_spaces/model_space.rb
Overview
a ModelSpace has a set of models registered with it, from which a Context can be created
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Util
all_model_superclasses, class_for_classname, class_from_classname, is_active_record_model?, model_from_name, name_from_model, require_for_classname
Constructor Details
Returns a new instance of ModelSpace.
24
25
26
27
|
# File 'lib/active_record/model_spaces/model_space.rb', line 24
def initialize(name)
@name = name.to_sym
@model_registrations = {}
end
|
Instance Attribute Details
#model_registrations ⇒ Object
Returns the value of attribute model_registrations.
22
23
24
|
# File 'lib/active_record/model_spaces/model_space.rb', line 22
def model_registrations
@model_registrations
end
|
#name ⇒ Object
Returns the value of attribute name.
21
22
23
|
# File 'lib/active_record/model_spaces/model_space.rb', line 21
def name
@name
end
|
Instance Method Details
#base_table_name(model) ⇒ Object
57
58
59
60
|
# File 'lib/active_record/model_spaces/model_space.rb', line 57
def base_table_name(model)
r = get_model_registration(model)
r[:base_table_name] || TableNames.base_table_name(r[:model])
end
|
#create_context(model_space_key) ⇒ Object
70
71
72
|
# File 'lib/active_record/model_spaces/model_space.rb', line 70
def create_context(model_space_key)
Context.new(self, model_space_key, ModelSpaces.create_persistor)
end
|
#deregister_model(model) ⇒ Object
37
38
39
|
# File 'lib/active_record/model_spaces/model_space.rb', line 37
def deregister_model(model)
delete_model_registration(model)
end
|
#history_versions(model) ⇒ Object
41
42
43
|
# File 'lib/active_record/model_spaces/model_space.rb', line 41
def history_versions(model)
get_model_registration(model)[:history_versions] || 0
end
|
#is_registered?(model) ⇒ Boolean
66
67
68
|
# File 'lib/active_record/model_spaces/model_space.rb', line 66
def is_registered?(model)
!!unchecked_get_model_registration(model)
end
|
#kill_context(model_space_key) ⇒ Object
74
75
76
77
|
# File 'lib/active_record/model_spaces/model_space.rb', line 74
def kill_context(model_space_key)
Context.drop_tables(self, model_space_key)
true
end
|
#register_model(model, opts = nil) ⇒ Object
29
30
31
32
33
34
35
|
# File 'lib/active_record/model_spaces/model_space.rb', line 29
def register_model(model, opts=nil)
raise "#{model} is not an ActiveRecord model Class" if !is_active_record_model?(model)
opts ||= {}
ModelSpaces.check_model_registration_keys(opts.keys)
set_model_registration(model, opts.merge(:model=>model))
self
end
|
#registered_model(model) ⇒ Object
49
50
51
|
# File 'lib/active_record/model_spaces/model_space.rb', line 49
def registered_model(model)
get_model_registration(model)[:model]
end
|
#registered_model_keys ⇒ Object
62
63
64
|
# File 'lib/active_record/model_spaces/model_space.rb', line 62
def registered_model_keys
self.model_registrations.keys
end
|
#registered_model_name(model) ⇒ Object
53
54
55
|
# File 'lib/active_record/model_spaces/model_space.rb', line 53
def registered_model_name(model)
name_from_model(get_model_registration(model)[:model])
end
|
#set_base_table_name(model, table_name) ⇒ Object
45
46
47
|
# File 'lib/active_record/model_spaces/model_space.rb', line 45
def set_base_table_name(model, table_name)
get_model_registration(model)[:base_table_name] = table_name
end
|