Class: SData::VirtualBase
Class Attribute Summary collapse
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
acts_as_sdata, find_by_sdata_instance_id
has_sdata_uuid
Methods included from PayloadMap
define_payload_map, has_sdata_association, has_sdata_attr
#sd_digest, #sd_sync_state, #sd_sync_state=
Constructor Details
#initialize(the_baze, the_type = nil) ⇒ VirtualBase
Returns a new instance of VirtualBase.
16
17
18
19
20
21
22
23
|
# File 'lib/s_data/virtual_base.rb', line 16
def initialize(the_baze, the_type=nil)
@uuid_class = SData::SdUuid
self.baze = the_baze
if self.respond_to?('sdata_type') && the_type
self.sdata_type = the_type
end
super()
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &block) ⇒ Object
26
27
28
29
30
31
32
|
# File 'lib/s_data/virtual_base.rb', line 26
def method_missing(meth, *args, &block)
if @payload
@payload.send(meth, *args, &block)
else
super
end
end
|
Class Attribute Details
.baze_class ⇒ Object
Returns the value of attribute baze_class.
7
8
9
|
# File 'lib/s_data/virtual_base.rb', line 7
def baze_class
@baze_class
end
|
Instance Attribute Details
#baze ⇒ Object
Returns the value of attribute baze.
13
14
15
|
# File 'lib/s_data/virtual_base.rb', line 13
def baze
@baze
end
|
Class Method Details
.all(*params) ⇒ Object
94
95
96
|
# File 'lib/s_data/virtual_base.rb', line 94
def self.all(*params)
self.collection(self.baze_class.all(*params))
end
|
.baze_class_name ⇒ Object
78
79
80
|
# File 'lib/s_data/virtual_base.rb', line 78
def self.baze_class_name
baze_class.nil? ? nil : baze_class.name.demodulize
end
|
.baze_classes ⇒ Object
TODO – should return all bb models that are used to composite the virtual model (or at least the subset whose modifications must be tracked)
74
75
76
|
# File 'lib/s_data/virtual_base.rb', line 74
def self.baze_classes
[self.baze_class]
end
|
.build_for(data, the_type = nil) ⇒ Object
50
51
52
53
54
55
56
|
# File 'lib/s_data/virtual_base.rb', line 50
def self.build_for(data, the_type=nil)
if data.is_a? Array
data.map {|item| virtual_base_for_object(item, the_type) }.compact
else
virtual_base_for_object(data, the_type)
end
end
|
.collection(arr) ⇒ Object
98
99
100
101
102
103
104
105
106
107
108
109
|
# File 'lib/s_data/virtual_base.rb', line 98
def self.collection(arr)
arr.map do |obj|
case obj
when VirtualBase, DeletedObjectProxy
obj
when ActiveRecord::Base
self.new(obj)
else
obj
end
end
end
|
.find(*params) ⇒ Object
86
87
88
|
# File 'lib/s_data/virtual_base.rb', line 86
def self.find(*params)
self.new(self.baze_class.find(*params))
end
|
.first(*params) ⇒ Object
90
91
92
|
# File 'lib/s_data/virtual_base.rb', line 90
def self.first(*params)
self.new(self.baze_class.first(*params))
end
|
.sdata_name ⇒ Object
82
83
84
|
# File 'lib/s_data/virtual_base.rb', line 82
def self.sdata_name
name.demodulize
end
|
.virtual_base_for_object(obj, the_type = nil) ⇒ Object
58
59
60
61
62
63
64
65
66
|
# File 'lib/s_data/virtual_base.rb', line 58
def self.virtual_base_for_object(obj, the_type=nil)
if obj
vb = self.new(obj, the_type)
vb = DeletedObjectProxy.from_virtual_base(vb) if obj.class.paranoid? && obj.deleted?
vb
else
nil
end
end
|
Instance Method Details
#baze_class_name ⇒ Object
34
35
36
|
# File 'lib/s_data/virtual_base.rb', line 34
def baze_class_name
self.class.baze_class_name
end
|
#owner ⇒ Object
68
69
70
|
# File 'lib/s_data/virtual_base.rb', line 68
def owner
raise "Security problem: owner not defined in subclass!"
end
|
#reference ⇒ Object
38
39
40
41
42
43
44
|
# File 'lib/s_data/virtual_base.rb', line 38
def reference
"#{self.baze.class.name.demodulize}_#{self.baze.id}"
end
|
#sd_class ⇒ Object
46
47
48
|
# File 'lib/s_data/virtual_base.rb', line 46
def sd_class
self.class.name
end
|