17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/ferris/core.rb', line 17
def region(name, class_name, &blk)
define_method("#{name}_region_object") do
class_name.base_url = self.class.base_url
class_name.new.tap do |region|
if block_given?
root = self.instance_exec(&blk)
return root.map {|root| class_name.new.tap {|region| region.root = root} } if root.respond_to?(:to_a)
region.root = root
end
end
end
self.instance_eval { private "#{name}_region_object" }
define_method("#{name}!") { self.class.region_list["@_#{name}"] ||= send("#{name}_region_object") }
define_method(name) { self.class.region_list["@_#{name}"] = send("#{name}_region_object") }
define_method("#{name}_present?") { [send(name)].flatten.map(&:root).map(&:present?).all? }
end
|