Class: Engine2::Meta
Direct Known Subclasses
BlobStoreMeta, ConfirmMeta, DecodeMeta, DeleteMetaBase, DownloadBlobStoreMeta, DownloadFileStoreMeta, DownloadForeignBlobStoreMeta, DummyMeta, FileStoreMeta, ForeignBlobStoreMeta, FormMeta, ListMeta, LoginMeta, LogoutFormMeta, LogoutMeta, MenuMeta, Engine2::MetaOnChangeSupport::OnChangeMeta, SaveMeta, StarToManyFieldUnlinkMeta, StarToManyLinkMeta, StarToManyUnlinkMetaBase, UploadBlobStoreMeta, UploadFileStoreMeta, ViewMeta
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(action, assets, static = self) ⇒ Meta
Returns a new instance of Meta.
22
23
24
25
26
27
|
# File 'lib/engine2/meta.rb', line 22
def initialize action, assets, static = self
@meta = {}
@action = action
@assets = assets
@static = static
end
|
Instance Attribute Details
Returns the value of attribute action.
4
5
6
|
# File 'lib/engine2/meta.rb', line 4
def action
@action
end
|
Returns the value of attribute assets.
4
5
6
|
# File 'lib/engine2/meta.rb', line 4
def assets
@assets
end
|
#invokable ⇒ Object
Returns the value of attribute invokable.
4
5
6
|
# File 'lib/engine2/meta.rb', line 4
def invokable
@invokable
end
|
Returns the value of attribute static.
4
5
6
|
# File 'lib/engine2/meta.rb', line 4
def static
@static
end
|
Class Method Details
.http_method(hm = nil) ⇒ Object
11
12
13
|
# File 'lib/engine2/meta.rb', line 11
def http_method hm = nil
hm ? @http_method = hm : @http_method
end
|
.inherited(cls) ⇒ Object
15
16
17
|
# File 'lib/engine2/meta.rb', line 15
def inherited cls
cls.http_method http_method
end
|
7
8
9
|
# File 'lib/engine2/meta.rb', line 7
def meta_type mt = nil
mt ? @meta_type = mt : @meta_type
end
|
Instance Method Details
#action_defined ⇒ Object
125
126
|
# File 'lib/engine2/meta.rb', line 125
def action_defined
end
|
41
42
43
|
# File 'lib/engine2/meta.rb', line 41
def check_static_meta
raise E2Error.new("Static meta required") if dynamic?
end
|
#dynamic? ⇒ Boolean
70
71
72
|
# File 'lib/engine2/meta.rb', line 70
def dynamic?
self != @static
end
|
101
102
103
104
105
106
|
# File 'lib/engine2/meta.rb', line 101
def freeze_meta
hash = @meta
hash.freeze
freeze
end
|
66
67
68
|
# File 'lib/engine2/meta.rb', line 66
def get
@meta
end
|
#http_method ⇒ Object
def self.method_added name
puts "ADDED #{name}"
end
33
34
35
|
# File 'lib/engine2/meta.rb', line 33
def http_method
@http_method
end
|
#invoke!(handler) ⇒ Object
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
# File 'lib/engine2/meta.rb', line 45
def invoke! handler
if rmp = @request_meta_proc
meta = self.class.new(action, assets, self)
meta.instance_exec(handler, *meta.request_meta_proc_params(handler), &rmp)
meta.post_process
{response: meta.invoke(handler), meta: meta.get}
else
response = invoke(handler)
if response.is_a?(Hash)
{response: response}
else
response
end
end
end
|
#lookup(*keys) ⇒ Object
def []= *keys, value
@meta.path!(*keys, value)
end
82
83
84
85
86
87
88
89
90
|
# File 'lib/engine2/meta.rb', line 82
def lookup *keys
if dynamic?
value = @meta.path(*keys)
value.nil? ? @static.get.path(*keys) : value
else
@meta.path(*keys)
end
end
|
#merge(*keys) ⇒ Object
92
93
94
95
96
97
98
99
|
# File 'lib/engine2/meta.rb', line 92
def merge *keys
if keys.length == 1
key = keys.first
dynamic? ? @static.get[key].merge(@meta[key] || {}) : @meta[key]
else
dynamic? ? @static.get.path(*keys).merge(@meta.path(*keys)) : @meta.path(*keys)
end
end
|
37
38
39
|
# File 'lib/engine2/meta.rb', line 37
def meta_type
@meta_type || (raise E2Error.new("No meta_type for meta #{self.class}"))
end
|
#post_process ⇒ Object
133
134
|
# File 'lib/engine2/meta.rb', line 133
def post_process
end
|
128
129
130
131
|
# File 'lib/engine2/meta.rb', line 128
def post_run
@invokable = respond_to?(:invoke)
post_process
end
|
120
121
122
123
|
# File 'lib/engine2/meta.rb', line 120
def pre_run
@meta_type = self.class.meta_type
@http_method = self.class.http_method
end
|
#request(&blk) ⇒ Object
112
113
114
115
116
117
118
|
# File 'lib/engine2/meta.rb', line 112
def request &blk
raise E2Error.new("No block given for request meta") unless blk
raise E2Error.new("Request meta already supplied") if @request_meta_proc
raise E2Error.new("No request block in request meta allowed") if dynamic?
@request_meta_proc = blk
nil
end
|
108
109
110
|
# File 'lib/engine2/meta.rb', line 108
def request_meta_proc_params handler
[]
end
|
#response(args) ⇒ Object
62
63
64
|
# File 'lib/engine2/meta.rb', line 62
def response args
(@meta[:response] ||= {}).merge!(args)
end
|
#split_keys(id) ⇒ Object
136
137
138
|
# File 'lib/engine2/meta.rb', line 136
def split_keys id
Sequel::split_keys(id)
end
|