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.
7
8
9
10
11
12
13
14
15
16
17
18
|
# File 'lib/bigamy/proxy.rb', line 7
def initialize parent, name, options
self.name = name
self.me = parent
self.primary_key = options.delete(:primary_key) || :id
self.klass = options.delete(:class) || target_klass
self.methods_added = Set.new
self.options = options
serialize_foreign_key
create_accessors
serialize_foreign_key
end
|
Instance Attribute Details
#foreign_key ⇒ Object
Returns the value of attribute foreign_key.
4
5
6
|
# File 'lib/bigamy/proxy.rb', line 4
def foreign_key
@foreign_key
end
|
#klass ⇒ Object
Returns the value of attribute klass.
4
5
6
|
# File 'lib/bigamy/proxy.rb', line 4
def klass
@klass
end
|
#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
32
33
34
|
# File 'lib/bigamy/proxy.rb', line 32
def add_getter
raise
end
|
#add_setter ⇒ Object
36
37
38
|
# File 'lib/bigamy/proxy.rb', line 36
def add_setter
raise
end
|
#create_accessors ⇒ Object
24
25
26
27
28
29
30
|
# File 'lib/bigamy/proxy.rb', line 24
def create_accessors
methods_added << name
methods_added << "#{name}="
add_getter
add_setter
end
|
#divorce_everyone ⇒ Object
48
49
50
51
|
# File 'lib/bigamy/proxy.rb', line 48
def divorce_everyone
methods_added.each {|m| me.send(:undef_method, m) if me.respond_to?(m)}
self.methods_added = Set.new
end
|
#root_klass ⇒ Object
61
62
63
|
# File 'lib/bigamy/proxy.rb', line 61
def root_klass
me
end
|
#root_klass_name ⇒ Object
65
66
67
|
# File 'lib/bigamy/proxy.rb', line 65
def root_klass_name
me.to_s.underscore.singularize.gsub('/', '_')
end
|
#serialize_foreign_key ⇒ Object
40
41
42
43
44
45
46
|
# File 'lib/bigamy/proxy.rb', line 40
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
53
54
55
|
# File 'lib/bigamy/proxy.rb', line 53
def target_klass
name.to_s.camelcase.singularize.constantize
end
|
#target_klass_name ⇒ Object
57
58
59
|
# File 'lib/bigamy/proxy.rb', line 57
def target_klass_name
name.to_s.underscore.singularize.gsub('/', '_')
end
|