Class: Bigamy::Proxy
- Inherits:
-
Object
show all
- Defined in:
- lib/bigamy/proxy.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(parent, name, options) ⇒ Proxy
Returns a new instance of Proxy.
6
7
8
9
10
11
12
13
14
15
16
|
# File 'lib/bigamy/proxy.rb', line 6
def initialize parent, name, options
self.name = name
self.me = parent
self.primary_key = options.delete(:primary_key) || :id
self.methods_added = Set.new
self.options = options
serialize_foreign_key
create_accessors
serialize_foreign_key
end
|
Instance Attribute Details
#me ⇒ Object
Returns the value of attribute me.
4
5
6
|
# File 'lib/bigamy/proxy.rb', line 4
def me
@me
end
|
#methods_added ⇒ Object
Returns the value of attribute methods_added.
4
5
6
|
# File 'lib/bigamy/proxy.rb', line 4
def methods_added
@methods_added
end
|
#name ⇒ Object
Returns the value of attribute name.
4
5
6
|
# File 'lib/bigamy/proxy.rb', line 4
def name
@name
end
|
#options ⇒ Object
Returns the value of attribute options.
4
5
6
|
# File 'lib/bigamy/proxy.rb', line 4
def options
@options
end
|
#primary_key ⇒ Object
Returns the value of attribute primary_key.
4
5
6
|
# File 'lib/bigamy/proxy.rb', line 4
def primary_key
@primary_key
end
|
Instance Method Details
#add_getter ⇒ Object
30
31
32
|
# File 'lib/bigamy/proxy.rb', line 30
def add_getter
raise
end
|
#add_setter ⇒ Object
34
35
36
|
# File 'lib/bigamy/proxy.rb', line 34
def add_setter
raise
end
|
#create_accessors ⇒ Object
22
23
24
25
26
27
28
|
# File 'lib/bigamy/proxy.rb', line 22
def create_accessors
methods_added << name
methods_added << "#{name}="
add_getter
add_setter
end
|
#divorce_everyone ⇒ Object
46
47
48
49
|
# File 'lib/bigamy/proxy.rb', line 46
def divorce_everyone
methods_added.each {|m| me.send(:undef_method, m) if me.respond_to?(m)}
self.methods_added = Set.new
end
|
#foreign_key ⇒ Object
18
19
20
|
# File 'lib/bigamy/proxy.rb', line 18
def foreign_key
raise
end
|
#root_klass ⇒ Object
60
61
62
|
# File 'lib/bigamy/proxy.rb', line 60
def root_klass
me
end
|
#root_klass_name ⇒ Object
64
65
66
|
# File 'lib/bigamy/proxy.rb', line 64
def root_klass_name
me.to_s.underscore.singularize.gsub('/', '_')
end
|
#serialize_foreign_key ⇒ Object
38
39
40
41
42
43
44
|
# File 'lib/bigamy/proxy.rb', line 38
def serialize_foreign_key
target_klass.class_eval " def \#{foreign_key}\n import_id_val read_val(:\#{foreign_key})\n end\n EOF\nend\n"
|
#target_klass ⇒ Object
Also known as:
klass
51
52
53
|
# File 'lib/bigamy/proxy.rb', line 51
def target_klass
options[:class] || name.to_s.camelcase.singularize.constantize
end
|
#target_klass_name ⇒ Object
56
57
58
|
# File 'lib/bigamy/proxy.rb', line 56
def target_klass_name
name.to_s.underscore.singularize.gsub('/', '_')
end
|