Module: Ferris::Region

Included in:
Core
Defined in:
lib/ferris/core.rb

Instance Method Summary collapse

Instance Method Details

#base_url(url = nil) ⇒ Object



13
14
15
# File 'lib/ferris/core.rb', line 13

def base_url(url = nil)
  @base_url ||= url
end

#region(name, class_name, &blk) ⇒ Object Also known as: page



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") }

  # TODO: Convert to .present? use
  define_method("#{name}_present?") { [send(name)].flatten.map(&:root).map(&:present?).all? }
end

#region_listObject



38
39
40
# File 'lib/ferris/core.rb', line 38

def region_list
  @regions ||= {}
end