odania 0.0.16 → 0.0.17

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +63 -21
  3. data/Guardfile +31 -0
  4. data/Rakefile +1 -0
  5. data/config/varnish_config.json +4 -2
  6. data/lib/odania/{plugin_config/models → config}/backend.rb +1 -1
  7. data/lib/odania/{plugin_config/models → config}/backend_group.rb +7 -2
  8. data/lib/odania/config/domain.rb +55 -0
  9. data/lib/odania/config/duplicates.rb +28 -0
  10. data/lib/odania/config/global_config.rb +154 -0
  11. data/lib/odania/config/internal.rb +48 -0
  12. data/lib/odania/config/layout.rb +35 -0
  13. data/lib/odania/config/page.rb +28 -0
  14. data/lib/odania/config/plugin_config.rb +51 -0
  15. data/lib/odania/config/style.rb +60 -0
  16. data/lib/odania/config/sub_domain.rb +125 -0
  17. data/lib/odania/config.rb +16 -0
  18. data/lib/odania/consul.rb +6 -2
  19. data/lib/odania/erb.rb +154 -0
  20. data/lib/odania/plugin.rb +12 -5
  21. data/lib/odania/plugin_config/{plugin_config.rb → base.rb} +26 -31
  22. data/lib/odania/varnish/generators/generate_backend_vcl.rb +12 -0
  23. data/lib/odania/varnish/generators/generate_site_vcl.rb +16 -0
  24. data/lib/odania/varnish/generators/generate_sites_vcl.rb +0 -4
  25. data/lib/odania/varnish.rb +11 -12
  26. data/lib/odania/version.rb +1 -1
  27. data/lib/odania.rb +7 -1
  28. data/odania.gemspec +3 -0
  29. data/spec/fixtures/global_config.json +142 -0
  30. data/spec/fixtures/plugin_config_1.json +93 -0
  31. data/spec/lib/odania/config/global_config_spec.rb +67 -0
  32. data/spec/lib/odania/config/plugin_config_spec.rb +28 -0
  33. data/spec/lib/odania/erb_spec.rb +16 -0
  34. data/spec/lib/odania/plugin_spec.rb +25 -0
  35. data/spec/lib/odania/varnish_spec.rb +37 -0
  36. data/spec/spec_helper.rb +15 -0
  37. data/spec/support/consul_mock.rb +116 -0
  38. data/tasks/odania.rake +1 -5
  39. data/templates/varnish/backend.vcl.erb +7 -1
  40. data/templates/varnish/catch_all.vcl.erb +1 -0
  41. data/templates/varnish/default.vcl.erb +1 -0
  42. data/templates/varnish/general.vcl.erb +29 -13
  43. data/templates/varnish/general_site.vcl.erb +33 -0
  44. data/templates/varnish/redirects.vcl.erb +1 -0
  45. data/templates/varnish/site.vcl.erb +18 -8
  46. data/templates/varnish/sites.vcl.erb +1 -1
  47. data/templates/varnish/websocker.vcl.erb +1 -0
  48. metadata +79 -19
  49. data/lib/odania/plugin_config/models/domain.rb +0 -38
  50. data/lib/odania/plugin_config/models/layout.rb +0 -31
  51. data/lib/odania/plugin_config/models/page.rb +0 -23
  52. data/lib/odania/plugin_config/models/redirect.rb +0 -20
  53. data/lib/odania/plugin_config/models/sub_domain.rb +0 -99
  54. data/lib/odania/template/asset.rb +0 -15
  55. data/lib/odania/template/config.rb +0 -15
  56. data/lib/odania/template/page.rb +0 -16
  57. data/lib/odania/template.rb +0 -8
  58. data/lib/odania/varnish/generators/generate_site_assets_vcl.rb +0 -27
  59. data/templates/varnish/site_assets.vcl.erb +0 -24
  60. /data/spec/{odania → lib}/odania_spec.rb +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d27b77aee7f7a7879b1bbee2a376f58f1654b812
4
- data.tar.gz: c5ceaebf77e1071d407805175c951b16d46d5e3a
3
+ metadata.gz: 3a5a520ac12de40571852067855b0471297d244c
4
+ data.tar.gz: 69685e1f55249f36906b3184e30336770c2f04c0
5
5
  SHA512:
6
- metadata.gz: 1c1e8c3902d96ce0b74998f7755a71e4874e7597fcaba907842ce4227ef621fb0046415892249f067a58046555a0cabd927362d50b1ecf348a0a72495b709f9f
7
- data.tar.gz: 0e8a2a31c990c247c550d224e2ff95c669d56df085c2993adabfa043d243029ca81db6cf04a39cdf722ada8da8da4a3181e7454bb86795a4333984025f82e3e2
6
+ metadata.gz: 2ca2320f73fedc397f662e0ce36955493af048d222af10d6824a17ec7e12e09997fedb525db3a116bf91caa70f0cebda3833062f0e294e6321e048ef20c17742
7
+ data.tar.gz: e4fdeee4b1352e3ed427b5a089b7d02e3a37edf8715d4fa123f45f37e20b11ffab7a487d6ecc639da22cc49632cef2993f095637fb585a522970bdded34eac1c
data/Gemfile.lock CHANGED
@@ -1,7 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- odania (0.0.16)
4
+ odania (0.0.17)
5
+ deep_merge
5
6
  diplomat
6
7
  erubis
7
8
  public_suffix
@@ -10,42 +11,81 @@ GEM
10
11
  remote: https://rubygems.org/
11
12
  specs:
12
13
  builder (3.2.2)
13
- cucumber (2.1.0)
14
+ coderay (1.1.0)
15
+ cucumber (2.3.2)
14
16
  builder (>= 2.1.2)
15
- cucumber-core (~> 1.3.0)
17
+ cucumber-core (~> 1.4.0)
18
+ cucumber-wire (~> 0.0.1)
16
19
  diff-lcs (>= 1.1.3)
17
- gherkin3 (~> 3.1.0)
20
+ gherkin (~> 3.2.0)
18
21
  multi_json (>= 1.7.5, < 2.0)
19
22
  multi_test (>= 0.1.2)
20
- cucumber-core (1.3.0)
21
- gherkin3 (~> 3.1.0)
23
+ cucumber-core (1.4.0)
24
+ gherkin (~> 3.2.0)
25
+ cucumber-wire (0.0.1)
26
+ deep_merge (1.0.1)
22
27
  diff-lcs (1.2.5)
23
- diplomat (0.14.0)
28
+ diplomat (0.15.0)
24
29
  faraday (~> 0.9)
25
30
  json (~> 1.8)
26
31
  erubis (2.7.0)
27
32
  faraday (0.9.2)
28
33
  multipart-post (>= 1.2, < 3)
29
- gherkin3 (3.1.2)
34
+ ffi (1.9.10)
35
+ formatador (0.2.5)
36
+ gherkin (3.2.0)
37
+ guard (2.13.0)
38
+ formatador (>= 0.2.4)
39
+ listen (>= 2.7, <= 4.0)
40
+ lumberjack (~> 1.0)
41
+ nenv (~> 0.1)
42
+ notiffany (~> 0.0)
43
+ pry (>= 0.9.12)
44
+ shellany (~> 0.0)
45
+ thor (>= 0.18.1)
46
+ guard-compat (1.2.1)
47
+ guard-rspec (4.6.4)
48
+ guard (~> 2.1)
49
+ guard-compat (~> 1.1)
50
+ rspec (>= 2.99.0, < 4.0)
30
51
  json (1.8.3)
52
+ listen (3.0.6)
53
+ rb-fsevent (>= 0.9.3)
54
+ rb-inotify (>= 0.9.7)
55
+ lumberjack (1.0.10)
56
+ method_source (0.8.2)
31
57
  multi_json (1.11.2)
32
58
  multi_test (0.1.2)
33
59
  multipart-post (2.0.0)
34
- public_suffix (1.5.2)
35
- rake (10.4.2)
36
- rspec (3.3.0)
37
- rspec-core (~> 3.3.0)
38
- rspec-expectations (~> 3.3.0)
39
- rspec-mocks (~> 3.3.0)
40
- rspec-core (3.3.2)
41
- rspec-support (~> 3.3.0)
42
- rspec-expectations (3.3.1)
60
+ nenv (0.3.0)
61
+ notiffany (0.0.8)
62
+ nenv (~> 0.1)
63
+ shellany (~> 0.0)
64
+ pry (0.10.3)
65
+ coderay (~> 1.1.0)
66
+ method_source (~> 0.8.1)
67
+ slop (~> 3.4)
68
+ public_suffix (1.5.3)
69
+ rake (10.5.0)
70
+ rb-fsevent (0.9.7)
71
+ rb-inotify (0.9.7)
72
+ ffi (>= 0.5.0)
73
+ rspec (3.4.0)
74
+ rspec-core (~> 3.4.0)
75
+ rspec-expectations (~> 3.4.0)
76
+ rspec-mocks (~> 3.4.0)
77
+ rspec-core (3.4.3)
78
+ rspec-support (~> 3.4.0)
79
+ rspec-expectations (3.4.0)
43
80
  diff-lcs (>= 1.2.0, < 2.0)
44
- rspec-support (~> 3.3.0)
45
- rspec-mocks (3.3.2)
81
+ rspec-support (~> 3.4.0)
82
+ rspec-mocks (3.4.1)
46
83
  diff-lcs (>= 1.2.0, < 2.0)
47
- rspec-support (~> 3.3.0)
48
- rspec-support (3.3.0)
84
+ rspec-support (~> 3.4.0)
85
+ rspec-support (3.4.1)
86
+ shellany (0.0.1)
87
+ slop (3.6.0)
88
+ thor (0.19.1)
49
89
 
50
90
  PLATFORMS
51
91
  ruby
@@ -53,6 +93,8 @@ PLATFORMS
53
93
  DEPENDENCIES
54
94
  bundler (~> 1.5)
55
95
  cucumber
96
+ guard
97
+ guard-rspec
56
98
  odania!
57
99
  rake
58
100
  rspec
data/Guardfile ADDED
@@ -0,0 +1,31 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ ## Uncomment and set this to only include directories you want to watch
5
+ # directories %w(app lib config test spec features)
6
+
7
+ ## Uncomment to clear the screen before every task
8
+ # clearing :on
9
+
10
+ ## Guard internally checks for changes in the Guardfile and exits.
11
+ ## If you want Guard to automatically start up again, run guard in a
12
+ ## shell loop, e.g.:
13
+ ##
14
+ ## $ while bundle exec guard; do echo "Restarting Guard..."; done
15
+ ##
16
+ ## Note: if you are using the `directories` clause above and you are not
17
+ ## watching the project directory ('.'), then you will want to move
18
+ ## the Guardfile to a watched dir and symlink it back, e.g.
19
+ #
20
+ # $ mkdir config
21
+ # $ mv Guardfile config/
22
+ # $ ln -s config/Guardfile .
23
+ #
24
+ # and, you'll have to watch "config/Guardfile" instead of "Guardfile"
25
+
26
+ guard :rspec, cmd: 'rspec' do
27
+ watch(%r{^spec/.+_spec\.rb$})
28
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
29
+ watch(%r{^lib/odania/config/(.+)\.rb$}) { |m| 'spec/lib/odania/config/plugin_config_spec.rb' }
30
+ watch('spec/spec_helper.rb') { 'spec' }
31
+ end
data/Rakefile CHANGED
@@ -1,3 +1,4 @@
1
1
  require 'bundler/gem_tasks'
2
+ require_relative 'lib/odania'
2
3
 
3
4
  Dir.glob('tasks/**/*.rake').each(&method(:import))
@@ -1,5 +1,7 @@
1
1
  {
2
- "name": "odania-varnish",
3
- "default": false,
2
+ "plugin-config": {
3
+ "name": "odania-varnish",
4
+ "default": false
5
+ },
4
6
  "domains": {}
5
7
  }
@@ -1,5 +1,5 @@
1
1
  module Odania
2
- module PluginConfig
2
+ module Config
3
3
  class Backend
4
4
  attr_accessor :service_name, :instance_name, :host, :port
5
5
 
@@ -1,10 +1,11 @@
1
1
  module Odania
2
- module PluginConfig
2
+ module Config
3
3
  class BackendGroup
4
- attr_accessor :name, :backends
4
+ attr_accessor :name, :backends, :core_backend
5
5
 
6
6
  def initialize(name, backends=[])
7
7
  self.name = name
8
+ self.core_backend = false
8
9
  self.backends = backends
9
10
  end
10
11
 
@@ -12,6 +13,10 @@ module Odania
12
13
  self.backends << backend
13
14
  end
14
15
 
16
+ def check_core_backend(tags)
17
+ self.core_backend = tags.include?('core-backend')
18
+ end
19
+
15
20
  def dump
16
21
  backend_data = []
17
22
  backends.each do |backend|
@@ -0,0 +1,55 @@
1
+ module Odania
2
+ module Config
3
+ class Domain
4
+ attr_accessor :name, :subdomains, :config, :redirects
5
+
6
+ def initialize(name)
7
+ self.name = name
8
+ reset
9
+ end
10
+
11
+ def add_subdomain(subdomain_name)
12
+ self.subdomains[subdomain_name]
13
+ end
14
+
15
+ def subdomain(name)
16
+ self.subdomains[name]
17
+ end
18
+
19
+ def dump
20
+ subdomain_data = {}
21
+ subdomains.each_pair do |name, subdomain|
22
+ subdomain_data[name] = subdomain.dump
23
+ end
24
+ subdomain_data
25
+ end
26
+
27
+ def load(data)
28
+ self.name = data['name'] unless data['name'].nil?
29
+ self.add(data)
30
+ end
31
+
32
+ def add(sub_domain_data, group_name=nil)
33
+ duplicates = Hash.new { |hash, key| hash[key] = [] }
34
+ unless sub_domain_data.nil?
35
+ sub_domain_data.each_pair do |name, data|
36
+ subdomain_duplicates = self.subdomains[name].add(data, group_name)
37
+ duplicates.deep_merge! subdomain_duplicates
38
+ end
39
+ end
40
+
41
+ duplicates
42
+ end
43
+
44
+ def [](key)
45
+ self.subdomains[key]
46
+ end
47
+
48
+ private
49
+
50
+ def reset
51
+ self.subdomains = Hash.new { |hash, key| hash[key] = SubDomain.new(key) }
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,28 @@
1
+ module Odania
2
+ module Config
3
+ class Duplicates
4
+ def initialize
5
+ @duplicates = Hash.new { |hash, key| hash[key] = Duplicate.new }
6
+ end
7
+
8
+ def add(type, key, group_name)
9
+ @duplicates[type].add(key, group_name)
10
+ end
11
+
12
+ def duplicates
13
+ @duplicates
14
+ end
15
+
16
+ class Duplicate
17
+ def initialize
18
+ @duplicate = {}
19
+ end
20
+
21
+ def add(key, group_name)
22
+ @duplicate[key] = [] if @duplicate[key].nil?
23
+ @duplicate[key] << group_name
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,154 @@
1
+ module Odania
2
+ module Config
3
+ class GlobalConfig < PluginConfig
4
+ # Load the global configuration
5
+ def load_global_config(config)
6
+ throw 'Invalid global config!' if config.nil?
7
+
8
+ reset
9
+ @default_backend_groups = config['default_backend_groups'] unless config['default_backend_groups'].nil?
10
+
11
+ unless config['domains'].nil?
12
+ config['domains'].each_pair do |name, data|
13
+ @domains[name].load(data)
14
+ end
15
+ end
16
+
17
+ # load backends from consul
18
+ Odania.plugin.get_all.each_pair do |name, instances|
19
+ instances.each do |instance|
20
+ add_backend(instance)
21
+ end
22
+ end
23
+
24
+ #puts config.inspect
25
+ #puts @backend_groups.inspect
26
+ #puts @default_backend_groups.inspect
27
+
28
+ self
29
+ end
30
+
31
+ def load_from_consul
32
+ Odania.plugin.get_all.each_pair do |plugin_name, instances|
33
+ puts "PLUGIN NAME #{plugin_name} - #{instances.count}" if $debug
34
+ instances.each do |instance|
35
+ add_backend(instance)
36
+ end
37
+
38
+ config = Odania.plugin.config_for plugin_name
39
+ next if config.nil?
40
+
41
+ begin
42
+ puts JSON.pretty_generate config if $debug
43
+ self.add_plugin_config(config)
44
+ rescue => e
45
+ puts 'Error loading configuration'
46
+ puts 'Config start ' + '+' * 50
47
+ puts JSON.pretty_generate config
48
+ puts 'Config end ' + '+' * 50
49
+ puts 'Error start ' + '+' * 50
50
+ puts e.inspect
51
+ puts 'Error end ' + '+' * 50
52
+ end
53
+ end
54
+ end
55
+
56
+ def generate_global_config
57
+ puts 'Loading plugin configs from consul'
58
+ load_from_consul
59
+
60
+ puts 'Generating global config'
61
+ config = self.dump
62
+ puts JSON.pretty_generate config if $debug
63
+ Odania.plugin.set_global_config config
64
+ config
65
+ end
66
+
67
+ # Add the configuration from the plugin
68
+ def add_plugin_config(plugin_cfg)
69
+ config_section = plugin_cfg['config']
70
+ group_name = plugin_cfg['plugin-config']['name']
71
+
72
+ if $debug
73
+ puts 'Loading configuration'
74
+ puts JSON.pretty_generate plugin_cfg
75
+ end
76
+
77
+ @plugin_config[group_name] = plugin_cfg['plugin-config']
78
+ @default_subdomains.deep_merge(plugin_cfg['default_subdomains']) unless plugin_cfg['default_subdomains'].nil?
79
+
80
+ # Add this service as a default backend if specified
81
+ @default_backend_groups << group_name if config_section['default']
82
+
83
+ # Add config
84
+ config_section.each_pair do |key, val|
85
+ unless @config[key].nil?
86
+ @duplicates.add :config, {key => 'already defined'}, group_name
87
+ end
88
+ end
89
+ @config.deep_merge! config_section
90
+
91
+ # Add Domain Information
92
+ unless plugin_cfg['domains'].nil?
93
+ plugin_cfg['domains'].each_pair do |name, data|
94
+ @domains[name].add(data, group_name).each do |duplicate_key, duplicate_data|
95
+ @duplicates.add duplicate_key, duplicate_data, group_name
96
+ end
97
+ end
98
+ end
99
+
100
+ true
101
+ end
102
+
103
+ def add_backend(backend_config)
104
+ return if backend_config.ServiceAddress.nil? or backend_config.ServiceAddress.empty?
105
+
106
+ backend = Backend.new(backend_config.ServiceName, backend_config.ServiceID, backend_config.ServiceAddress, backend_config.ServicePort)
107
+ @backend_groups[backend_config.ServiceName].add_backend backend
108
+ @backend_groups[backend_config.ServiceName].check_core_backend backend_config.ServiceTags
109
+ end
110
+
111
+ def reset
112
+ super
113
+
114
+ @default_backend_groups = []
115
+ @duplicates = Duplicates.new
116
+ @backend_groups = Hash.new { |hash, key| hash[key] = BackendGroup.new(key) }
117
+ @default_subdomains = {}
118
+
119
+ @domains['_general'].add_subdomain('_general')
120
+ end
121
+
122
+ def duplicates
123
+ @duplicates.duplicates
124
+ end
125
+
126
+ def backend_groups
127
+ @backend_groups
128
+ end
129
+
130
+ def default_backend
131
+ group_name = @default_backend_groups.first
132
+ group_name = @backend_groups.keys.first if group_name.nil?
133
+ raise 'No backend found' if @backend_groups.empty?
134
+ @backend_groups[group_name].backends.first
135
+ end
136
+
137
+ def default_subdomains
138
+ @default_subdomains
139
+ end
140
+
141
+ def default_redirects
142
+ general = @domains['_general'].subdomain('_general')
143
+ return {} if general.nil?
144
+ general.redirects
145
+ end
146
+
147
+ def dump
148
+ cfg = super
149
+ cfg['default_backend_groups'] = @default_backend_groups
150
+ cfg
151
+ end
152
+ end
153
+ end
154
+ end
@@ -0,0 +1,48 @@
1
+ module Odania
2
+ module Config
3
+ class Internal
4
+ attr_accessor :partials, :layouts
5
+
6
+ def initialize
7
+ reset
8
+ end
9
+
10
+ def load(data)
11
+ reset
12
+ unless data['partials'].nil?
13
+ data['partials'].each_pair do |name, data|
14
+ self.partials[name].load(data)
15
+ end
16
+ end
17
+
18
+ unless data['layouts'].nil?
19
+ data['layouts'].each_pair do |name, data|
20
+ self.layouts[name].load(data)
21
+ end
22
+ end
23
+ end
24
+
25
+ def dump
26
+ partial_data = {}
27
+ partials.each_pair do |web_url, page|
28
+ partial_data[web_url] = page.dump
29
+ end
30
+
31
+ layout_data = {}
32
+ layouts.each_pair do |web_url, page|
33
+ layout_data[web_url] = page.dump
34
+ end
35
+
36
+ {
37
+ 'layouts' => layout_data,
38
+ 'partials' => partial_data
39
+ }
40
+ end
41
+
42
+ def reset
43
+ self.layouts = Hash.new { |hash, key| hash[key] = Layout.new }
44
+ self.partials = Hash.new { |hash, key| hash[key] = Page.new }
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,35 @@
1
+ module Odania
2
+ module Config
3
+ class Layout
4
+ attr_accessor :styles
5
+
6
+ def initialize
7
+ reset
8
+ end
9
+
10
+ def dump
11
+ style_data = {}
12
+ styles.each_pair do |name, style|
13
+ style_data[name] = style.dump
14
+ end
15
+
16
+ result = {}
17
+ result['styles'] =style_data unless style_data.nil?
18
+ result
19
+ end
20
+
21
+ def load(data)
22
+ reset
23
+ unless data['styles'].nil?
24
+ data['styles'].each_pair do |key, val|
25
+ self.styles[key].load(val)
26
+ end
27
+ end
28
+ end
29
+
30
+ def reset
31
+ self.styles = Hash.new { |hash, key| hash[key] = Style.new(key) }
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,28 @@
1
+ module Odania
2
+ module Config
3
+ class Page
4
+ attr_accessor :group_name, :plugin_url, :cacheable, :expires
5
+
6
+ def dump
7
+ result = {}
8
+ result['group_name'] = self.group_name unless self.group_name.nil?
9
+ result['plugin_url'] = self.plugin_url unless self.plugin_url.nil?
10
+ result['cacheable'] = self.cacheable unless self.cacheable.nil?
11
+ result['expires'] = self.expires unless self.expires.nil?
12
+ result
13
+ end
14
+
15
+ def load(data, group_name=nil)
16
+ self.group_name = data['group_name'] unless data['group_name'].nil?
17
+ self.group_name = group_name unless group_name.nil?
18
+ self.plugin_url = data['plugin_url']
19
+ self.cacheable = data['cacheable'] unless data['cacheable'].nil?
20
+ self.expires = data['expires'] unless data['expires'].nil?
21
+ end
22
+
23
+ def director
24
+ "#{Odania.varnish_sanitize(self.group_name)}_director"
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,51 @@
1
+ module Odania
2
+ module Config
3
+ class PluginConfig
4
+ attr_accessor :domains, :config, :default_subdomains, :plugin_config
5
+
6
+ def initialize
7
+ reset
8
+ end
9
+
10
+ # Load the global configuration
11
+ def load(data)
12
+ reset
13
+ @config = data['config'] unless data['config'].nil?
14
+ @plugin_config = data['plugin-config'] unless data['plugin-config'].nil?
15
+ @default_subdomains = data['default_subdomains'] unless data['default_subdomains'].nil?
16
+ unless data['domains'].nil?
17
+ data['domains'].each_pair do |name, data|
18
+ @domains[name].load(data)
19
+ end
20
+ end
21
+
22
+ true
23
+ end
24
+
25
+ def [](key)
26
+ @domains[key]
27
+ end
28
+
29
+ # Reset configuration
30
+ def reset
31
+ @config = {}
32
+ @plugin_config = {}
33
+ @domains = Hash.new { |hash, key| hash[key] = Domain.new(key) }
34
+ end
35
+
36
+ def dump
37
+ domain_data = {}
38
+ @domains.each_pair do |name, domain|
39
+ domain_data[name] = domain.dump
40
+ end
41
+
42
+ {
43
+ 'plugin-config' => plugin_config,
44
+ 'config' => config,
45
+ 'default_subdomains' => @default_subdomains,
46
+ 'domains' => domain_data
47
+ }
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,60 @@
1
+ module Odania
2
+ module Config
3
+ class Style
4
+ attr_accessor :name, :entry_point, :direct, :dynamic
5
+
6
+ def initialize(name)
7
+ self.name = name
8
+ reset
9
+ end
10
+
11
+ def plugins(type, key)
12
+ @plugins[type][key]
13
+ end
14
+
15
+ def dump
16
+ direct_data = {}
17
+ direct.each_pair do |web_url, page|
18
+ direct_data[web_url] = page.dump
19
+ end
20
+
21
+ dynamic_data = {}
22
+ dynamic.each_pair do |web_url, page|
23
+ dynamic_data[web_url] = page.dump
24
+ end
25
+
26
+ {
27
+ 'entry_point' => entry_point,
28
+ 'direct' => direct_data,
29
+ 'dynamic' => dynamic_data
30
+ }
31
+ end
32
+
33
+ def load(data)
34
+ reset
35
+ self.entry_point = data['entry_point'] unless data['entry_point'].nil?
36
+
37
+ unless data['direct'].nil?
38
+ data['direct'].each_pair do |name, data|
39
+ self.direct[name].load(data)
40
+ end
41
+ end
42
+
43
+ unless data['dynamic'].nil?
44
+ data['dynamic'].each_pair do |name, data|
45
+ self.dynamic[name].load(data)
46
+ end
47
+ end
48
+ end
49
+
50
+ private
51
+
52
+ def reset
53
+ self.entry_point = nil
54
+ self.direct = Hash.new { |hash, key| hash[key] = Page.new }
55
+ self.dynamic = Hash.new { |hash, key| hash[key] = Page.new }
56
+ @plugins = {:direct => Hash.new { |hash, key| hash[key] = [] }, :dynamic => Hash.new { |hash, key| hash[key] = [] }}
57
+ end
58
+ end
59
+ end
60
+ end