choices 0.2.4 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. data/README.md +46 -30
  2. data/lib/choices/rails.rb +13 -0
  3. metadata +34 -54
data/README.md CHANGED
@@ -1,49 +1,65 @@
1
- The choice is yours
2
- ===================
1
+ Choices for Rails
2
+ =================
3
3
 
4
4
  Easy-peasy external settings for your Rails app.
5
5
 
6
- # Gemfile
7
- gem 'choices'
6
+ ~~~ rb
7
+ # Gemfile
8
+ gem 'choices'
9
+ ~~~
8
10
 
9
11
  In your app initializer block:
10
12
 
11
- config.from_file 'settings.yml'
13
+ ~~~ rb
14
+ config.from_file 'settings.yml'
15
+ ~~~
12
16
 
13
- This will read configuration from "config/settings.yml" and, additionally, "settings.local.yml" if it exists. You should check the main file into version control, but not the ".local" file which is to be used for per-machine configuration: tweaks in development or private keys in production, for example.
17
+ This will read configuration from "config/settings.yml" and, additionally,
18
+ "settings.local.yml" if it exists. You should check the main file into version
19
+ control, but not the ".local" file which is to be used for per-machine
20
+ configuration: tweaks in development or private keys in production, for example.
14
21
 
15
- # .gitignore
16
- config/settings.local.yml
22
+ ~~~
23
+ # .gitignore
24
+ config/settings.local.yml
25
+ ~~~
17
26
 
18
- Configuration files can contain ERB; this is useful for reading in Heroku configuration. For example:
27
+ Configuration files can contain ERB; this is useful for reading in dynamic
28
+ config such as from environment variables:
19
29
 
20
- # settings.yml
21
- defaults: &defaults
22
- secret_token: <%= ENV['COOKIE_SECRET'] %>
23
- heroku: <%= !!ENV['HEROKU_TYPE'] %>
24
- mongodb:
25
- uri: <%= ENV['MONGOHQ_URL'] %>
30
+ ~~~ yaml
31
+ # settings.yml
32
+ defaults: &defaults
33
+ secret_token: <%= ENV['COOKIE_SECRET'] %>
34
+ heroku: <%= !!ENV['HEROKU_TYPE'] %>
35
+ mongodb:
36
+ uri: <%= ENV['MONGOHQ_URL'] %>
26
37
 
27
- development:
28
- <<: *defaults
38
+ development:
39
+ <<: *defaults
29
40
 
30
- test: &testing
31
- <<: *defaults
32
- secret_token: <%= "banana" * 5 %>
33
- mongodb:
34
- database: myapp_test
41
+ test: &testing
42
+ <<: *defaults
43
+ secret_token: <%= "banana" * 5 %>
44
+ mongodb:
45
+ database: myapp_test
35
46
 
36
- cucumber:
37
- <<: *testing
47
+ cucumber:
48
+ <<: *testing
49
+ ~~~
38
50
 
39
51
  The ".local" file can contain overrides for your development environment:
40
52
 
41
- # settings.local.yml
42
- development:
43
- mongodb:
44
- database: myapp_dev
53
+ ~~~ yaml
54
+ # settings.local.yml
55
+ development:
56
+ mongodb:
57
+ database: myapp_dev
58
+ ~~~
45
59
 
46
60
  Finally, the config keys can be read in your app as such:
47
61
 
48
- Rails.configuration.heroku #=> false
49
- Rails.configuration.mongodb.database #=> "myapp_dev"
62
+ ~~~ rb
63
+ Rails.configuration.heroku #=> false
64
+ Rails.configuration.mongodb.database #=> "myapp_dev"
65
+ ~~~
@@ -1,3 +1,4 @@
1
+ require 'hashie/mash'
1
2
  require 'choices'
2
3
 
3
4
  module Choices::Rails
@@ -21,6 +22,18 @@ module Choices::Rails
21
22
  @choices.update settings
22
23
 
23
24
  settings.each do |key, value|
25
+ old_value = self.respond_to?(key) ? self.send(key) : nil
26
+
27
+ if "Rails::OrderedOptions" == old_value.class.name
28
+ # convert from Array to a real Hash
29
+ old_value = old_value.inject({}) {|h,(k,v)| h[k]=v; h }
30
+ end
31
+
32
+ if Hash === value and Hash === old_value
33
+ # don't overwrite existing Hash values; deep update them
34
+ value = Hashie::Mash.new(old_value).update value
35
+ end
36
+
24
37
  self.send("#{key}=", value)
25
38
  end
26
39
  end
metadata CHANGED
@@ -1,85 +1,65 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: choices
3
- version: !ruby/object:Gem::Version
4
- hash: 31
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.0
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 2
9
- - 4
10
- version: 0.2.4
11
6
  platform: ruby
12
- authors:
13
- - "Mislav Marohni\xC4\x87"
7
+ authors:
8
+ - Mislav Marohnić
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2011-02-18 00:00:00 +01:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
12
+ date: 2012-12-12 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
22
15
  name: hashie
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
25
17
  none: false
26
- requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- hash: 15
30
- segments:
31
- - 0
32
- - 4
33
- - 0
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
34
21
  version: 0.4.0
35
22
  type: :runtime
36
- version_requirements: *id001
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 0.4.0
37
30
  description:
38
31
  email: mislav.marohnic@gmail.com
39
32
  executables: []
40
-
41
33
  extensions: []
42
-
43
34
  extra_rdoc_files: []
44
-
45
- files:
35
+ files:
46
36
  - Rakefile
47
37
  - lib/choices/rails.rb
48
38
  - lib/choices.rb
49
39
  - README.md
50
- has_rdoc: false
51
- homepage: http://github.com/mislav/choices
40
+ homepage: https://github.com/mislav/choices
52
41
  licenses: []
53
-
54
42
  post_install_message:
55
43
  rdoc_options: []
56
-
57
- require_paths:
44
+ require_paths:
58
45
  - lib
59
- required_ruby_version: !ruby/object:Gem::Requirement
46
+ required_ruby_version: !ruby/object:Gem::Requirement
60
47
  none: false
61
- requirements:
62
- - - ">="
63
- - !ruby/object:Gem::Version
64
- hash: 3
65
- segments:
66
- - 0
67
- version: "0"
68
- required_rubygems_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ! '>='
50
+ - !ruby/object:Gem::Version
51
+ version: '0'
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
53
  none: false
70
- requirements:
71
- - - ">="
72
- - !ruby/object:Gem::Version
73
- hash: 3
74
- segments:
75
- - 0
76
- version: "0"
54
+ requirements:
55
+ - - ! '>='
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
77
58
  requirements: []
78
-
79
59
  rubyforge_project:
80
- rubygems_version: 1.5.0
60
+ rubygems_version: 1.8.23
81
61
  signing_key:
82
62
  specification_version: 3
83
63
  summary: Easy settings for your app
84
64
  test_files: []
85
-
65
+ has_rdoc: