Class: Odania::Config::PageBase

Inherits:
Object
  • Object
show all
Defined in:
lib/odania/config/page_base.rb

Direct Known Subclasses

Style, SubDomain

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePageBase

Returns a new instance of PageBase.



6
7
8
# File 'lib/odania/config/page_base.rb', line 6

def initialize
	reset
end

Instance Attribute Details

#directObject

Returns the value of attribute direct.



4
5
6
# File 'lib/odania/config/page_base.rb', line 4

def direct
  @direct
end

#dynamicObject

Returns the value of attribute dynamic.



4
5
6
# File 'lib/odania/config/page_base.rb', line 4

def dynamic
  @dynamic
end

Instance Method Details

#[](type) ⇒ Object



39
40
41
42
# File 'lib/odania/config/page_base.rb', line 39

def [](type)
	return self.direct if 'direct'.eql? type.to_s
	self.dynamic
end

#add(data, group_name = nil) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/odania/config/page_base.rb', line 10

def add(data, group_name=nil)
	duplicates = Hash.new { |hash, key| hash[key] = [] }
	unless data['direct'].nil?
		data['direct'].each_pair do |name, direct_data|
			duplicates[:direct] << name if self.direct.key? name
			self.direct[name].load(direct_data, group_name)
		end
	end

	unless data['dynamic'].nil?
		data['dynamic'].each_pair do |name, dynamic_data|
			duplicates[:dynamic] << name if self.direct.key? name
			self.dynamic[name].load(dynamic_data, group_name)
		end
	end
	duplicates
end

#dumpObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/odania/config/page_base.rb', line 44

def dump
	direct_data = {}
	direct.each_pair do |web_url, page|
		direct_data[web_url] = page.dump
	end

	dynamic_data = {}
	dynamic.each_pair do |web_url, page|
		dynamic_data[web_url] = page.dump
	end

	{
		'direct' => direct_data,
		'dynamic' => dynamic_data
	}
end

#load(data, group_name) ⇒ Object



28
29
30
# File 'lib/odania/config/page_base.rb', line 28

def load(data, group_name)
	self.add(data, group_name)
end

#resetObject



32
33
34
35
36
37
# File 'lib/odania/config/page_base.rb', line 32

def reset
	self.direct = Hash.new { |hash, key| hash[key] = Page.new }
	self.dynamic = Hash.new { |hash, key| hash[key] = Page.new }

	@plugins = {:direct => Hash.new { |hash, key| hash[key] = [] }, :dynamic => Hash.new { |hash, key| hash[key] = [] }}
end