application_configuration 1.2.2 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/README ADDED
@@ -0,0 +1,50 @@
1
+ There are no setters available for the configuration settings. You have to edit the files in order to update the settings.
2
+ To retrieve a setting:
3
+ app_config.setting_name
4
+
5
+ or
6
+ Application::Configuration.setting_name
7
+ In Rails the load order of configuration files is as follows:
8
+ application_configuration.yml
9
+ application_configuration_RAILS_ENV.yml
10
+ Configuration settings behave just like Rails environment files do. If you have a configuration setting specified in both application_configuration.yml and application_configuration_development.yml the setting in application_configuration_development.yml will override the the one in application_configuration.yml.
11
+ # application_configuration.yml:
12
+ email_address: help@helium.com
13
+
14
+ # application_configuration_development.yml:
15
+ email_address: help@localhost
16
+
17
+ # console in development mode:
18
+ app_config.email_address # => 'help@localhost'
19
+
20
+ # console in production or test mode:
21
+ app_config.email_address # => 'help@helium.com'
22
+ Settings get reloaded every minute by default. There is no need to restart the app if you make a config file change. This can be changed by setting the following in your config yml file:
23
+ reload_settings_every: <%= 24.hours %> # or some other length of time.
24
+ Settings can be namespaced. In order to help better ‘group’ settings together. Settings in the yml files can be namespace using the familiar Ruby syntax of ’::’:
25
+ my::name: "mark bates"
26
+ my::email: "mbates@helium.com"
27
+
28
+ # console:
29
+ app_config.my.name # => "mark bates"
30
+ app_config.my.email # => "mbates@helium.com
31
+
32
+ app_config.my__name # => "mark bates"
33
+ app_config.my__email # => "mbates@helium.com" #notice the double '_'
34
+ The config yml files get run through ERB so you can do things like:
35
+ time_right_now: <%= Time.now %>
36
+ twenty_four_hours: <%= 1.day %>
37
+ To load additional files put the following in environment.rb (or your specific environment if you want to only load them in a particular environment):
38
+ app_config.load_file(full_path_to_file)
39
+
40
+ or
41
+ Application::Configuration.load_file(full_path_to_file)
42
+
43
+ Anything you set in this new file will override, if any, settings from the other files previously loaded. You can call ‘load_file’ as many times as you would like to load as many files as you like. The order in which you load the files determines the precedent for settings getting overridden, so make sure you load them in the correct sequence. The order in which these files get loaded in will be preserved on subsequent reloads of the settings.
44
+ To reload settings you simply need to do the following:
45
+ app_config.reload
46
+
47
+ or
48
+ Application::Configuration.reload
49
+
50
+ Keep in mind that if you’re trying to reload the settings for your running app, it will do you no good to go into a console window and type this command as the settings are cached per instance of your rails app, and opening a console window is a different instance then the one currently running in mongel. If you wish to reload your settings on every request you can put this command in your application.rb file. But make sure you REMOVE it before you check in.
@@ -1,3 +1,4 @@
1
+ require 'rubygems'
1
2
  require 'singleton'
2
3
  require 'yaml'
3
4
  require 'erb'
@@ -0,0 +1,162 @@
1
+ require File.join(File.dirname(__FILE__), 'test_helper')
2
+ require 'webrick'
3
+ include WEBrick
4
+
5
+ class ConfServlet < HTTPServlet::AbstractServlet
6
+ def do_GET(request, response)
7
+ # puts "request: #{request.inspect}"
8
+ h = {"url_test" => "remote", "some_remote_config" => "wizbang!"}
9
+ response.status = 200
10
+ response.body = h.to_yaml
11
+ response["Content-Type"] = "text/yaml"
12
+ end
13
+
14
+ alias :do_POST :do_GET
15
+ end
16
+
17
+ class ConfServer
18
+
19
+ class << self
20
+
21
+ attr_accessor :server
22
+
23
+ def start
24
+ server = HTTPServer.new(:Port => 8000)
25
+ server.mount("/conf", ConfServlet)
26
+
27
+ ["TERM", "INT"].each do |signal|
28
+ trap(signal){server.shutdown}
29
+ end
30
+ server.start
31
+ end
32
+
33
+ def stop
34
+ server.shutdown
35
+ end
36
+
37
+ end
38
+
39
+ end
40
+
41
+
42
+ class ApplicationConfigurationUnitTest < Test::Unit::TestCase
43
+
44
+ def setup
45
+ Application::Configuration.whiny_config_missing = false
46
+ end
47
+
48
+ def teardown
49
+ Application::Configuration.whiny_config_missing = true
50
+ end
51
+
52
+ def test_false
53
+ assert !app_config.should_be_false
54
+ assert_not_nil app_config.should_be_false
55
+ end
56
+
57
+ def test_param_doesnt_exist
58
+ assert_nil Application::Configuration.asldkfjasdfkljasdfsldj
59
+ end
60
+
61
+ def test_loads_application_configuration
62
+ assert_equal "bar", Application::Configuration.foo
63
+ assert_equal 4, Application::Configuration.four
64
+ assert_equal({"one" => 1, "two" => 2, "three" => 3}, Application::Configuration.my_hash)
65
+ assert_equal Time.now.beginning_of_month, Time.parse(Application::Configuration.my_time)
66
+ assert_equal([1, 2, 3, "mark", "bates"], Application::Configuration.my_array)
67
+ end
68
+
69
+ def test_environment_overrides
70
+ assert_equal "rock!", Application::Configuration.pickles
71
+ end
72
+
73
+ def test_reload_every
74
+ time = Application::Configuration.instance.last_reload_time
75
+ assert_not_nil time
76
+ assert_equal "bar", Application::Configuration.foo
77
+ sleep(3)
78
+ assert_equal "bar", Application::Configuration.foo
79
+ assert Application::Configuration.instance.last_reload_time > time
80
+ end
81
+
82
+ def test_nested_arrays
83
+ assert_equal([["Pro", "Con"], ["Yes", "No"], ["For", "Against"], ["Agree", "Disagree"], ["Support", "Oppose"], ["True", "False"], ["Innocent", "Guilty"], ["Right", "Wrong"]], Application::Configuration.all_debate_pairing_options)
84
+ end
85
+
86
+ def test_namespaces
87
+ assert_equal "my foo", Application::Configuration::instance.final_configuration_settings["my__foo"]
88
+ assert_equal "my foo", Application::Configuration.my__foo
89
+ assert_equal "my foo", Application::Configuration.my.foo
90
+ assert_equal Application::Configuration.my__foo, Application::Configuration.my.foo
91
+ assert_equal "marky kang", Application::Configuration::mark__name
92
+ assert_equal "marky kang", Application::Configuration::mark.name
93
+ assert_equal Application::Configuration::mark__name, Application::Configuration::mark.name
94
+ end
95
+
96
+ def test_object_hook
97
+ assert_equal Application::Configuration.pickles, app_config.pickles
98
+ end
99
+
100
+ def test_load_file
101
+ # assert_nil Application::Configuration.add
102
+ assert_nil Application::Configuration.add
103
+ assert_instance_of Application::Configuration, Application::Configuration.load_file("#{RAILS_ROOT}/config/application_configuration_additional.yml")
104
+ assert_equal 2, Application::Configuration.add
105
+ assert_equal "bar", Application::Configuration.foo
106
+ Application::Configuration.reload
107
+ assert_equal 2, Application::Configuration.add
108
+ assert_equal "bar", Application::Configuration.foo
109
+ end
110
+
111
+ def test_load_file_not_found
112
+ assert_nil Application::Configuration.load_file("asldfjasdfljasdflsdfjasdl")
113
+ end
114
+
115
+ def test_load_url_not_found
116
+ assert_nil Application::Configuration.load_url("asldfjasdfljasdflsdfjasdl")
117
+ end
118
+
119
+ def test_load_url
120
+ t = Thread.new do
121
+ ConfServer.start
122
+ end
123
+ sleep(2)
124
+ assert_nil Application::Configuration.some_remote_config
125
+ assert_equal "local", Application::Configuration.url_test
126
+ assert_instance_of Application::Configuration, Application::Configuration.load_url("http://localhost:8000/conf")
127
+ assert_equal "wizbang!", Application::Configuration.some_remote_config
128
+ assert_equal "remote", Application::Configuration.url_test
129
+ end
130
+
131
+ def test_load_hash
132
+ # puts "start of test_load_hash:"
133
+ assert_nil app_config.some_hash_config
134
+ # puts "load hash:"
135
+ app_config.load_hash({"some_hash_config" => 1}, :test_load_hash_settings)
136
+ assert_equal 1, app_config.some_hash_config
137
+ # puts "reload"
138
+ app_config.reload
139
+ assert_equal 1, app_config.some_hash_config
140
+ # puts "load_hash 2"
141
+ app_config.load_hash({"some_hash_config" => 2}, :test_load_hash_settings_two)
142
+ assert_equal 2, app_config.some_hash_config
143
+ # puts "reload 2"
144
+ app_config.reload
145
+ assert_equal 2, app_config.some_hash_config
146
+ end
147
+
148
+ def test_revert
149
+ assert_nil app_config.my_revert_test
150
+ app_config.load_hash({:my_revert_test => 1}, :revert_test_1)
151
+ assert_equal 1, app_config.my_revert_test
152
+ app_config.revert
153
+ assert_nil app_config.my_revert_test
154
+ 5.times do |i|
155
+ app_config.load_hash({:my_revert_test => i}, "revert_test_#{i}")
156
+ assert_equal i, app_config.my_revert_test
157
+ end
158
+ app_config.revert(2)
159
+ assert_equal 2, app_config.my_revert_test
160
+ end
161
+
162
+ end
@@ -0,0 +1,113 @@
1
+ foo: bar
2
+ four: <%= 2 + 2 %>
3
+ my_hash:
4
+ one: 1
5
+ two: 2
6
+ three: <%= 1 + 2 %>
7
+ my_time: <%= Time.now.beginning_of_month %>
8
+ my_array:
9
+ - 1
10
+ - 2
11
+ - 3
12
+ - mark
13
+ - bates
14
+ pickles: are yummy!
15
+ mark::name: "marky kang"
16
+ url_test: local
17
+ radiant_server_url: http://localhost:3001
18
+ cms_layouts:
19
+ about: my_test_layout
20
+ foo: another_layout
21
+ default_cms_layout: application
22
+ radiant_server_time_out: <%= 1.second %>
23
+ whiny_config_missing: false
24
+ reload_settings_every: <%= 1.hour %>
25
+
26
+ # rails_sales_visa:
27
+ # gateway: paypal
28
+ # login: seller_1193780413_biz_api1.helium.com
29
+ # password: VJ4SZRNE6TB7T6Q5
30
+
31
+ rails_sales_default:
32
+ # gateway: paypal
33
+ # login: seller_1193780413_biz_api1.helium.com
34
+ # password: VJ4SZRNE6TB7T6Q5
35
+ gateway: authorize_net
36
+ login: 2fD6yH48
37
+ password: 29AVG493Sh4j6utn
38
+
39
+ rails_sales_currency_type_default: USD
40
+
41
+ page_cache_storage: cachetastic
42
+
43
+ album_cache_options:
44
+ servers:
45
+ - 127.0.0.1:11211
46
+
47
+ doctor_be_cache_options:
48
+ adapter: drb
49
+ store_options:
50
+ host: "druby://127.0.0.1:61676"
51
+
52
+ doctor_ce_cache_options:
53
+ adapter: drb
54
+ store_options:
55
+ host: "druby://127.0.0.1:61676"
56
+
57
+ cachetastic_caches_page_cache_options:
58
+ default_expiry: <%= 1.hour %>
59
+ expiry_swing: <%= 15.minutes %>
60
+
61
+ cachetastic_caches_rails_session_cache_options:
62
+ adapter: local_memory
63
+ store_options:
64
+ dir: /cachetastic/
65
+
66
+ memcache_benchmark_cache_options:
67
+ debug: false
68
+ adapter: memcache
69
+ marshall_method: none
70
+ store_options:
71
+ c_threshold: 10_000
72
+ compression: true
73
+ debug: false
74
+ readonly: false
75
+ urlencode: false
76
+
77
+ my_file_store_cache_options:
78
+ debug: false
79
+ adapter: file
80
+ store_options:
81
+ dir: "/cachetastic/test"
82
+
83
+ file_benchmark_cache_options:
84
+ debug: false
85
+ adapter: file
86
+ store_options:
87
+ dir: "/cachetastic/benchmark"
88
+
89
+ local_memory_benchmark_cache_options:
90
+ debug: false
91
+ adapter: local_memory
92
+
93
+ cachetastic_default_options:
94
+ debug: true
95
+ adapter: local_memory
96
+ marshall_method: none
97
+ default_expiry: <%= 24.hours %>
98
+ # buffer: simple
99
+ # store_options:
100
+ # c_threshold: 10_000
101
+ # compression: true
102
+ # debug: false
103
+ # readonly: false
104
+ # urlencode: false
105
+ logging:
106
+ # logger_1:
107
+ # type: file
108
+ # file: log/memcached.log
109
+ logger_2:
110
+ type: console
111
+ level: error
112
+ # servers:
113
+ # - 127.0.0.1:11211
@@ -0,0 +1 @@
1
+ add: <%= 1 + 1 %>
@@ -0,0 +1,54 @@
1
+ pickles: rock!
2
+ reload_settings_every: <%= 2.seconds %>
3
+ my::foo: "my foo"
4
+ whiny_config_missing: false
5
+ all_debate_pairing_options:
6
+ -
7
+ - "Pro"
8
+ - "Con"
9
+ -
10
+ - "Yes"
11
+ - "No"
12
+ -
13
+ - "For"
14
+ - "Against"
15
+ -
16
+ - "Agree"
17
+ - "Disagree"
18
+ -
19
+ - "Support"
20
+ - "Oppose"
21
+ -
22
+ - "True"
23
+ - "False"
24
+ -
25
+ - "Innocent"
26
+ - "Guilty"
27
+ -
28
+ - "Right"
29
+ - "Wrong"
30
+
31
+ foo_bar_cache_options:
32
+ default_expiry: <%= 3.seconds %>
33
+ adapter: local_memory
34
+ marshall_method: yaml
35
+
36
+ your_temp_options_cache_options:
37
+ adapter: file
38
+ store_options:
39
+ dir: /cachetastic/test
40
+
41
+ cachetastic_default_options:
42
+ debug: true
43
+ adapter: local_memory
44
+ marshall_method: none
45
+ default_expiry: <%= 24.hours %>
46
+ logging:
47
+ # logger_1:
48
+ # type: file
49
+ # file: log/memcached.log
50
+ logger_2:
51
+ type: console
52
+ level: debug
53
+
54
+ should_be_false: false
@@ -0,0 +1,12 @@
1
+ require 'rubygems'
2
+ require "test/unit"
3
+ require 'rake'
4
+ require 'fileutils'
5
+ require 'facets/times'
6
+ require File.join(File.dirname(__FILE__), "..", "lib", "application_configuration")
7
+
8
+ RAILS_ENV = "test"
9
+ RAILS_ROOT = File.join(File.dirname(__FILE__), "rails")
10
+
11
+ class Test::Unit::TestCase
12
+ end
metadata CHANGED
@@ -1,42 +1,37 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: application_configuration
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.2
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - markbates
8
8
  autorequire:
9
- - application_configuration
10
9
  bindir: bin
11
10
  cert_chain: []
12
11
 
13
- date: 2008-04-07 00:00:00 -04:00
12
+ date: 2008-06-04 00:00:00 -04:00
14
13
  default_executable:
15
14
  dependencies: []
16
15
 
17
- description: "application_configuration was developed by: markbates"
18
- email:
16
+ description: A simple system for configuring Ruby applications.
17
+ email: mark@mackframework.com
19
18
  executables: []
20
19
 
21
20
  extensions: []
22
21
 
23
- extra_rdoc_files: []
24
-
22
+ extra_rdoc_files:
23
+ - README
25
24
  files:
26
- - application_configuration-1.2.2.gem
27
- - init.rb
28
25
  - lib/application_configuration.rb
29
- - lib/tasks/rubyforge_config.yml
30
- has_rdoc: false
31
- homepage:
26
+ - README
27
+ has_rdoc: true
28
+ homepage: http://www.mackframework.com
32
29
  post_install_message:
33
30
  rdoc_options: []
34
31
 
35
32
  require_paths:
36
33
  - lib
37
34
  - lib
38
- - lib
39
- - lib/tasks
40
35
  required_ruby_version: !ruby/object:Gem::Requirement
41
36
  requirements:
42
37
  - - ">="
@@ -52,9 +47,15 @@ required_rubygems_version: !ruby/object:Gem::Requirement
52
47
  requirements: []
53
48
 
54
49
  rubyforge_project: magrathea
55
- rubygems_version: 1.0.1
50
+ rubygems_version: 1.1.1
56
51
  signing_key:
57
52
  specification_version: 2
58
- summary: application_configuration
59
- test_files: []
60
-
53
+ summary: A simple system for configuring Ruby applications.
54
+ test_files:
55
+ - test/application_configuration_unit_test.rb
56
+ - test/rails
57
+ - test/rails/config
58
+ - test/rails/config/application_configuration.yml
59
+ - test/rails/config/application_configuration_additional.yml
60
+ - test/rails/config/application_configuration_test.yml
61
+ - test/test_helper.rb
File without changes
data/init.rb DELETED
@@ -1 +0,0 @@
1
- # require 'application_configuration'
@@ -1,5 +0,0 @@
1
- --- !ruby/object:RubyForgeConfig
2
- gem_name: application_configuration
3
- package: application_configuration
4
- project: magrathea
5
- version: 1.2.2