anyway_config 0.4.0 → 0.5.1.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (77) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +4 -1
  3. data/.rubocop.yml +38 -0
  4. data/.travis.yml +18 -25
  5. data/CHANGELOG.md +21 -0
  6. data/Gemfile +11 -3
  7. data/LICENSE.txt +1 -1
  8. data/README.md +82 -47
  9. data/Rakefile +18 -5
  10. data/anyway_config.gemspec +15 -11
  11. data/config/cool.yml +5 -0
  12. data/gemfiles/rails42.gemfile +1 -2
  13. data/gemfiles/rails5.gemfile +6 -0
  14. data/gemfiles/railsmaster.gemfile +6 -0
  15. data/lib/anyway.rb +3 -5
  16. data/lib/anyway/config.rb +52 -31
  17. data/lib/anyway/env.rb +60 -61
  18. data/lib/anyway/ext/class.rb +18 -0
  19. data/lib/anyway/ext/deep_dup.rb +34 -0
  20. data/lib/anyway/ext/hash.rb +34 -0
  21. data/lib/anyway/rails/config.rb +16 -7
  22. data/lib/anyway/version.rb +5 -3
  23. data/lib/anyway_config.rb +3 -0
  24. data/spec/anyway.yml +1 -1
  25. data/spec/config_spec.rb +30 -19
  26. data/spec/config_spec_norails.rb +59 -16
  27. data/spec/dummy/config.ru +0 -4
  28. data/spec/dummy/config/application.rb +3 -12
  29. data/spec/dummy/config/cool.yml +1 -1
  30. data/spec/dummy/config/environments/test.rb +0 -37
  31. data/spec/dummy/config/routes.rb +0 -54
  32. data/spec/dummy/config/secrets.yml +0 -1
  33. data/spec/env_spec.rb +18 -14
  34. data/spec/ext/deep_dup_spec.rb +38 -0
  35. data/spec/spec_helper.rb +21 -9
  36. data/spec/spec_norails_helper.rb +18 -5
  37. data/spec/support/cool_config.rb +9 -3
  38. data/spec/support/test_config.rb +14 -3
  39. metadata +26 -80
  40. data/gemfiles/rails32.gemfile +0 -7
  41. data/gemfiles/rails40.gemfile +0 -7
  42. data/gemfiles/rails41.gemfile +0 -7
  43. data/spec/dummy.yml +0 -0
  44. data/spec/dummy/README.rdoc +0 -28
  45. data/spec/dummy/Rakefile +0 -6
  46. data/spec/dummy/app/assets/images/.keep +0 -0
  47. data/spec/dummy/app/assets/javascripts/application.js +0 -13
  48. data/spec/dummy/app/assets/stylesheets/application.css +0 -15
  49. data/spec/dummy/app/controllers/application_controller.rb +0 -5
  50. data/spec/dummy/app/controllers/concerns/.keep +0 -0
  51. data/spec/dummy/app/helpers/application_helper.rb +0 -2
  52. data/spec/dummy/app/mailers/.keep +0 -0
  53. data/spec/dummy/app/models/.keep +0 -0
  54. data/spec/dummy/app/models/concerns/.keep +0 -0
  55. data/spec/dummy/app/views/layouts/application.html.erb +0 -14
  56. data/spec/dummy/bin/bundle +0 -3
  57. data/spec/dummy/bin/rails +0 -4
  58. data/spec/dummy/bin/rake +0 -4
  59. data/spec/dummy/config/environments/development.rb +0 -37
  60. data/spec/dummy/config/environments/production.rb +0 -83
  61. data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -7
  62. data/spec/dummy/config/initializers/cookies_serializer.rb +0 -3
  63. data/spec/dummy/config/initializers/filter_parameter_logging.rb +0 -4
  64. data/spec/dummy/config/initializers/inflections.rb +0 -16
  65. data/spec/dummy/config/initializers/mime_types.rb +0 -4
  66. data/spec/dummy/config/initializers/session_store.rb +0 -3
  67. data/spec/dummy/config/initializers/wrap_parameters.rb +0 -14
  68. data/spec/dummy/config/locales/en.yml +0 -23
  69. data/spec/dummy/db/migrate/20140730133818_add_testos.rb +0 -11
  70. data/spec/dummy/db/migrate/20140731162044_add_column_to_testos.rb +0 -5
  71. data/spec/dummy/db/schema.rb +0 -22
  72. data/spec/dummy/lib/assets/.keep +0 -0
  73. data/spec/dummy/log/.keep +0 -0
  74. data/spec/dummy/public/404.html +0 -67
  75. data/spec/dummy/public/422.html +0 -67
  76. data/spec/dummy/public/500.html +0 -66
  77. data/spec/dummy/public/favicon.ico +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 458041a187fa4057159e72a80b71b2f5c2110b18
4
- data.tar.gz: e96284b36eea6da6390ea0ebf2e029f7ebda186c
3
+ metadata.gz: 2bccd0227df51b6e96f2036d7863eadd0b0bbc07
4
+ data.tar.gz: 70d571464f14b6881c9cfcafe5af9ad367e24161
5
5
  SHA512:
6
- metadata.gz: 4b677bda47bc679d8d50b80a930904f13678ffb36533fc9ccbc05f1e5dd39d549173995abd532dc47b7a70958fe7f381e423a6b77524a0fbcec69ebaa649c481
7
- data.tar.gz: a9ca0a93fbfc54679a06665a0b67ce9b9fa8be644a62c81be196c392cf511d01a4e3a54eaf68ea07de7591eb5e3bace8acb6a221761225e191c64c243c329047
6
+ metadata.gz: 38d485231332fdb6d4be36a5a12a20eef21d0c4cbbfdb9077c2a5454998b36ed4c1ff4cfd522b0e91bb5bb3f97fd118f8df47ff1a20c42d85f2fdd452bd364ab
7
+ data.tar.gz: 1e52529cd706d22621e6ef6d50fe2605f727d92c6d8b643ba17224745a40c4e6b0b4f4b448b2e9b83cf5e7d80353278ea55516c8b0a1d039699a2cce28505e31
data/.gitignore CHANGED
@@ -32,5 +32,8 @@ spec/dummy/db/*.sqlite3-journal
32
32
  spec/dummy/tmp/
33
33
 
34
34
  Gemfile.lock
35
+ Gemfile.local
35
36
  .rspec
36
- *.gem
37
+ *.gem
38
+
39
+ tmp/
data/.rubocop.yml ADDED
@@ -0,0 +1,38 @@
1
+ AllCops:
2
+ Include:
3
+ - 'lib/**/*.rb'
4
+ - 'lib/**/*.rake'
5
+ - 'spec/**/*.rb'
6
+ - 'Gemfile'
7
+ - 'Rakefile'
8
+ Exclude:
9
+ - 'bin/**/*'
10
+ - 'spec/dummy/**/*'
11
+ - 'tmp/**/*'
12
+ - 'gemfiles/vendor/**/*'
13
+ - 'vendor/**/*'
14
+ DisplayCopNames: true
15
+ StyleGuideCopsOnly: false
16
+ TargetRubyVersion: 2.3
17
+
18
+ Style/Documentation:
19
+ Exclude:
20
+ - 'spec/**/*.rb'
21
+
22
+ Style/StringLiterals:
23
+ Enabled: false
24
+
25
+ Style/BlockDelimiters:
26
+ Exclude:
27
+ - 'spec/**/*.rb'
28
+
29
+ Metrics/MethodLength:
30
+ Exclude:
31
+ - 'spec/**/*.rb'
32
+
33
+ Metrics/BlockLength:
34
+ Exclude:
35
+ - 'spec/**/*.rb'
36
+
37
+ Metrics/LineLength:
38
+ Max: 100
data/.travis.yml CHANGED
@@ -1,33 +1,26 @@
1
1
  language: ruby
2
2
  cache: bundler
3
- rvm:
4
- - 2.2
3
+
4
+ dist: trusty
5
+ sudo: false
5
6
 
6
7
  notifications:
7
8
  email: false
8
9
 
9
- matrix:
10
- allow_failures:
11
- - rvm: :jruby
10
+ before_install:
11
+ - gem install bundler
12
+ - gem update bundler
12
13
 
14
+ matrix:
13
15
  include:
14
- - rvm: 1.9.3
15
- gemfile: gemfiles/rails32.gemfile
16
-
17
- - rvm: jruby
18
- gemfile: gemfiles/rails32.gemfile
19
-
20
- - rvm: 2.0.0
21
- gemfile: gemfiles/rails40.gemfile
22
-
23
- - rvm: 2.1
24
- gemfile: gemfiles/rails40.gemfile
25
-
26
- - rvm: jruby
27
- gemfile: gemfiles/rails41.gemfile
28
-
29
- - rvm: 2.1
30
- gemfile: gemfiles/rails41.gemfile
31
-
32
- - rvm: 2.1
33
- gemfile: gemfiles/rails42.gemfile
16
+ - rvm: ruby-head
17
+ gemfile: gemfiles/railsmaster.gemfile
18
+ - rvm: 2.4.1
19
+ gemfile: gemfiles/rails5.gemfile
20
+ - rvm: 2.3.1
21
+ gemfile: gemfiles/rails42.gemfile
22
+ - rvm: 2.2.3
23
+ gemfile: gemfiles/rails42.gemfile
24
+ allow_failures:
25
+ - rvm: ruby-head
26
+ gemfile: gemfiles/railsmaster.gemfile
data/CHANGELOG.md ADDED
@@ -0,0 +1,21 @@
1
+ # Change log
2
+
3
+ ## 1.0.0 (2017-06-20)
4
+
5
+ - Lazy load and parse ENV configurtaion (https://github.com/palkan/anyway_config/commit/5fe407c75fefec8994ca201ea7b4691b5ddd96e5). ([@palkan][])
6
+
7
+ - Add support for ERB in YML configuration (https://github.com/palkan/anyway_config/commit/8d8a47dbda6858a43ff509aaa4cddf4f938dd660). ([@palkan][])
8
+
9
+ ## 0.5.0 (2017-01-20)
10
+
11
+ - Drop `active_support` dependency. ([@palkan][])
12
+
13
+ Use custom refinements instead of requiring `active_support`.
14
+
15
+ No we're dependency-free!
16
+
17
+ ## 0.1.0 (2015-01-20)
18
+
19
+ Initial version.
20
+
21
+ [@palkan]: https://github.com/palkan
data/Gemfile CHANGED
@@ -1,7 +1,15 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  # Specify your gem's dependencies in anyway_config.gemspec
4
- gem 'rails', '~> 4.2'
5
- gem 'pry-byebug'
6
6
  gem 'sqlite3'
7
- gemspec
7
+ gemspec
8
+
9
+ local_gemfile = "#{File.dirname(__FILE__)}/Gemfile.local"
10
+
11
+ if File.exist?(local_gemfile)
12
+ eval(File.read(local_gemfile)) # rubocop:disable Security/Eval
13
+ else
14
+ gem 'rails', '~> 5.0'
15
+ end
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2015 palkan
1
+ Copyright (c) 2017 palkan
2
2
 
3
3
  MIT License
4
4
 
data/README.md CHANGED
@@ -1,39 +1,52 @@
1
- [![Build Status](https://travis-ci.org/palkan/anyway_config.svg?branch=master)](https://travis-ci.org/palkan/anyway_config)
1
+ [![Gem Version](https://badge.fury.io/rb/anyway_config.svg)](https://rubygems.org/gems/anyway_config) [![Build Status](https://travis-ci.org/palkan/anyway_config.svg?branch=master)](https://travis-ci.org/palkan/anyway_config)
2
2
 
3
3
  # Anyway Config
4
4
 
5
- Rails/Ruby plugin/application configuration using any source: YAML, _secrets_, environment.
5
+ Rails/Ruby plugin/application configuration tool which allows you to load parameters from different sources: YAML, Rails secrets, environment.
6
6
 
7
+ Apps using AnywayConfig:
7
8
 
8
- Apps using Anyway Config:
9
- - [influxer](https://github.com/palkan/influxer).
9
+ - [Influxer](https://github.com/palkan/influxer)
10
10
 
11
- ## Using with Gem
11
+ - [AnyCable](https://github.com/anycable/anycable)
12
12
 
13
- Configure your gemspec
13
+ - [and others](https://github.com/palkan/anyway_config/network/dependents).
14
+
15
+ ## Installation
16
+
17
+ 1) Adding to a gem:
14
18
 
15
19
  ```ruby
16
- Gem::Specification.new do |s|
20
+ # my-cool-gem.gemspec
21
+ Gem::Specification.new do |spec|
17
22
  ...
18
- s.add_dependancy 'anyway_config', "~>0.4"
23
+ spec.add_dependancy "anyway_config", "~> 1.0"
19
24
  ...
20
25
  end
21
26
  ```
22
27
 
23
- And then execute:
28
+ 2) Adding to your project:
24
29
 
25
- $ bundle
30
+ ```ruby
31
+ # Gemfile
32
+ gem "anyway_config", "~> 1.0"
33
+ ```
26
34
 
27
- Or install it yourself as:
35
+ 3) Install globally:
28
36
 
29
- $ gem install anyway_config
37
+ ```sh
38
+ $ gem install anyway_config
39
+ ```
30
40
 
31
- ### Usage
41
+ ## Usage
42
+
43
+ ### Pre-defined configuration
32
44
 
33
45
  Create configuration class:
34
46
 
35
47
  ```ruby
36
48
  require 'anyway'
49
+
37
50
  module MyCoolGem
38
51
  class Config < Anyway::Config
39
52
  attr_config user: 'root', password: 'root', host: 'localhost'
@@ -47,11 +60,21 @@ end
47
60
  attr_config :user, :password, host: 'localhost'
48
61
  ```
49
62
 
50
- Your config will be filled up with values from `RAILS_ROOT/config/my_cool_gem.yml`, `Rails.application.secrets.my_cool_gem` (if using Rails) and `ENV['MYCOOLGEM_*']`.
63
+ Then create an instance of the config class and use it:
64
+
65
+ ```ruby
66
+ module MyCoolGem
67
+ def self.config
68
+ @config ||= Config.new
69
+ end
70
+ end
71
+
72
+ MyCoolGem.config.user #=> 'root'
73
+ ```
51
74
 
52
- ### Customize name
75
+ #### Customize name
53
76
 
54
- If you want to load config params from, for example, "cool.yml" (secrets, env), just add one line:
77
+ By default, AnywayConfig uses the namespace (the outer module name) as the config name, but you can set it manually:
55
78
 
56
79
  ```ruby
57
80
  module MyCoolGem
@@ -62,30 +85,41 @@ module MyCoolGem
62
85
  end
63
86
  ```
64
87
 
65
- ### Config clear and reload
88
+ ### Dynamic configuration
66
89
 
67
- You can use `clear` and `reload` functions on your config (which do exactly what they state).
90
+ You can also create configuration objects without pre-defined schema (just like `Rails.application.config_for` but more [powerful](#railsapplicationconfig_for-vs-anywayconfigfor)):
68
91
 
92
+ ```ruby
93
+ # load data from config/my_app.yml, secrets.my_app (if using Rails), ENV["MYAPP_*"]
94
+ config = Anyway::Config.for(:my_app)
95
+ ```
69
96
 
70
- ## Using with Rails app
97
+ ### Using with Rails
71
98
 
72
- In your Gemfile
99
+ Your config will be filled up with values from the following sources (ordered by priority from low to high):
73
100
 
74
- ```ruby
75
- require 'anyway_config', "~>0.4"
76
- ```
101
+ - `RAILS_ROOT/config/my_cool_gem.yml` (for the current `RAILS_ENV`, supports `ERB`)
77
102
 
78
- In your code
103
+ - `Rails.application.secrets.my_cool_gem`
79
104
 
80
- ```ruby
105
+ - `ENV['MYCOOLGEM_*']`.
81
106
 
82
- config = Anyway::Config.for(:my_app) # load data from config/my_app.yml, secrets.my_app, ENV["MYAPP_*"]
107
+ ### Using with Ruby
108
+
109
+ By default AnywayConfig is looking for a config YAML at `./config/<config-name>.yml`. You can override this setting
110
+ through special environment variable – 'MYGEM_CONF' – containing the path to the YAML file.
111
+
112
+ Environmental variables work the same way as with Rails.
113
+
114
+
115
+ ### Config clear and reload
116
+
117
+ There are `#clear` and `#reload` functions on your config (which do exactly what they state).
83
118
 
84
- ```
85
119
 
86
120
  ## `Rails.application.config_for` vs `Anyway::Config.for`
87
121
 
88
- Rails 4.2 introduces new feature: `Rails.application.config_for`. It looks very similar to
122
+ Rails 4.2 introduced new feature: `Rails.application.config_for`. It looks very similar to
89
123
  `Anyway::Config.for`, but there are some differences:
90
124
 
91
125
  | Feature | Rails | Anyway |
@@ -94,27 +128,33 @@ Rails 4.2 introduces new feature: `Rails.application.config_for`. It looks very
94
128
  | load data from `secrets` | no | yes |
95
129
  | load data from environment | no | yes |
96
130
  | return Hash with indifferent access | no | yes |
97
- | support ERB within `config/app.yml` | yes | no |
131
+ | support ERB within `config/app.yml` | yes | yes* |
98
132
  | raise errors if file doesn't exist | yes | no |
99
133
 
100
- But the main advantage of Anyway::Config is that it's supported in Rails >= 3.2, Ruby >= 1.9.3.
101
- And it can be even used [without Rails](#using-without-rails)!
134
+ <sub><sup>*</sup>make sure that ERB is loaded</sub>
135
+
136
+ But the main advantage of Anyway::Config is that it can be used [without Rails](#using-with-ruby)!)
102
137
 
103
138
  ## How to set env vars
104
139
 
105
- Environmental variables for your config should start with your module name (or config name if any), uppercased and underscore-free.
140
+ Environmental variables for your config should start with your config name, uppercased and underscore-free.
141
+
142
+ For example, if your module is called "MyCoolGem" then the env var "MYCOOLGEM_PASSWORD" is used as `config.password`.
106
143
 
107
- For example, if your module is called "MyCoolGem" then your env var "MYCOOLGEM_PASSWORD" is used as `config.password`.
144
+ Environment variables are type-casted (case-insensitive).
108
145
 
109
- Environment variables are type-casted (case-insensitive).
110
146
  Examples:
111
- - "True", "T" and "yes" to `true`;
112
- - "False", "f" and "no" to `false`;
113
- - "nil" and "null" to `nil` (do you really need it?);
114
- - "123" to 123 and "3.14" to 3.14.
115
147
 
116
- *Anyway Config* supports nested (_hashed_) environmental variables. Just separate keys with double-underscore.
117
- For example, "MYCOOLGEM_OPTIONS__VERBOSE" is transformed to `config.options.verbose`.
148
+ - `"True"`, `"t"` and `"yes"` to `true`;
149
+
150
+ - `"False"`, `"f"` and `"no"` to `false`;
151
+
152
+ - `"nil"` and `"null"` to `nil` (do you really need it?);
153
+
154
+ - `"123"` to 123 and `"3.14"` to 3.14.
155
+
156
+ *Anyway Config* supports nested (_hashed_) env variables. Just separate keys with double-underscore.
157
+ For example, "MYCOOLGEM_OPTIONS__VERBOSE" is parsed as `config.options.verbose`.
118
158
 
119
159
  Array values are also supported:
120
160
 
@@ -123,21 +163,16 @@ Array values are also supported:
123
163
  config.ids #=> [1,2,3]
124
164
  ```
125
165
 
126
- If you want to provide text-like env variable which contain commas then wrap it into quotes:
166
+ If you want to provide a text-like env variable which contains commas then wrap it into quotes:
127
167
 
128
168
  ```ruby
129
169
  MYCOOLGEM="Nif-Nif, Naf-Naf and Nouf-Nouf"
130
170
  ```
131
171
 
132
- ## Using without Rails
133
-
134
- AnywayConfig can be used without Rails too.
135
- Environmental variables remain the same. To load config from YAML add special environment variable 'MYGEM_CONF' containing path to config. But you cannot use one file for different environments (unless you do it yourself).
136
-
137
172
  ## Contributing
138
173
 
139
174
  1. Fork it
140
175
  2. Create your feature branch (`git checkout -b my-new-feature`)
141
176
  3. Commit your changes (`git commit -am 'Add some feature'`)
142
177
  4. Push to the branch (`git push origin my-new-feature`)
143
- 5. Create a new Pull Request
178
+ 5. Create a new Pull Request
data/Rakefile CHANGED
@@ -1,10 +1,23 @@
1
- require "bundler/gem_tasks"
1
+ # frozen_string_literal: true
2
2
 
3
+ require "bundler/gem_tasks"
3
4
  require 'rspec/core/rake_task'
4
- RSpec::Core::RakeTask.new(:spec)
5
+ require "rubocop/rake_task"
6
+
7
+ RuboCop::RakeTask.new
8
+
9
+ task(:spec).clear
10
+ desc "Run specs with Rails app"
11
+ RSpec::Core::RakeTask.new("spec") do |task|
12
+ task.exclude_pattern = "spec/**/*_norails.rb"
13
+ task.verbose = false
14
+ end
5
15
 
6
- RSpec::Core::RakeTask.new(:spec2) do |t|
7
- t.pattern = "./spec/**/*_norails.rb"
16
+ desc "Run acceptance specs without Rails"
17
+ RSpec::Core::RakeTask.new("spec:norails") do |task|
18
+ task.pattern = "spec/**/*_norails.rb"
19
+ task.verbose = false
8
20
  end
9
21
 
10
- task :default => [:spec2, :spec]
22
+ desc "Run the all specs and linters"
23
+ task default: %w[spec:norails spec rubocop]
@@ -1,4 +1,6 @@
1
1
  # coding: utf-8
2
+ # frozen_string_literal: true
3
+
2
4
  lib = File.expand_path('../lib', __FILE__)
3
5
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
6
  require 'anyway/version'
@@ -6,21 +8,23 @@ require 'anyway/version'
6
8
  Gem::Specification.new do |s|
7
9
  s.name = "anyway_config"
8
10
  s.version = Anyway::VERSION
9
- s.authors = ["Vlad Dem"]
11
+ s.authors = ["Vladimir Dementyev"]
10
12
  s.email = ["dementiev.vm@gmail.com"]
11
13
  s.homepage = "http://github.com/palkan/anyway_config"
12
- s.summary = "Configuration for Rails plugins and applications"
13
- s.description = "Configuration for Rails plugins and applications"
14
- s.license = "MIT"
14
+ s.summary = "Configuration DSL for Ruby libraries and applications"
15
+ s.description = %{
16
+ Configuration DSL for Ruby libraries and applications.
15
17
 
16
- s.files = `git ls-files`.split($/)
17
- s.require_paths = ["lib"]
18
- s.required_ruby_version = '>= 1.9.3'
18
+ Allows you to easily follow the twevle factor application principles (https://12factor.net/config).
19
+ }
19
20
 
20
- s.add_dependency "activesupport", ">= 3.2"
21
+ s.license = "MIT"
22
+
23
+ s.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
24
+ s.require_paths = ["lib"]
25
+ s.required_ruby_version = '>= 2'
21
26
 
22
- s.add_development_dependency 'pry'
23
27
  s.add_development_dependency "simplecov", ">= 0.3.8"
24
- s.add_development_dependency "rspec", "~> 3.0.0"
25
- s.add_development_dependency "rspec-rails", "~> 3.0.0"
28
+ s.add_development_dependency "rspec", "~> 3.5.0"
29
+ s.add_development_dependency "rubocop", "~> 0.49"
26
30
  end