setty 1.0.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 (58) hide show
  1. data/.gitignore +18 -0
  2. data/.rspec +2 -0
  3. data/.travis.yml +9 -0
  4. data/CHANGELOG.md +5 -0
  5. data/Gemfile +4 -0
  6. data/LICENSE.txt +22 -0
  7. data/README.md +165 -0
  8. data/Rakefile +7 -0
  9. data/example/.env +1 -0
  10. data/example/.gitignore +16 -0
  11. data/example/.rspec +1 -0
  12. data/example/Gemfile +15 -0
  13. data/example/README.md +13 -0
  14. data/example/Rakefile +6 -0
  15. data/example/app/assets/stylesheets/application.css.scss +31 -0
  16. data/example/app/assets/stylesheets/reset.css +43 -0
  17. data/example/app/controllers/application_controller.rb +3 -0
  18. data/example/app/controllers/examples_controller.rb +4 -0
  19. data/example/app/views/examples/index.html.slim +27 -0
  20. data/example/app/views/layouts/application.html.slim +10 -0
  21. data/example/bin/bundle +3 -0
  22. data/example/bin/rails +4 -0
  23. data/example/bin/rake +4 -0
  24. data/example/config.ru +4 -0
  25. data/example/config/application.rb +21 -0
  26. data/example/config/boot.rb +4 -0
  27. data/example/config/custom_settings.yml +7 -0
  28. data/example/config/custom_settings/products.yml +5 -0
  29. data/example/config/custom_settings/uploads.yml +6 -0
  30. data/example/config/database.yml +12 -0
  31. data/example/config/environment.rb +5 -0
  32. data/example/config/environments/development.rb +29 -0
  33. data/example/config/environments/test.rb +37 -0
  34. data/example/config/initializers/secret_token.rb +12 -0
  35. data/example/config/initializers/session_store.rb +3 -0
  36. data/example/config/initializers/setty.rb +1 -0
  37. data/example/config/routes.rb +3 -0
  38. data/example/db/schema.rb +16 -0
  39. data/example/log/.keep +0 -0
  40. data/example/public/favicon.ico +0 -0
  41. data/example/spec/features/settings_spec.rb +7 -0
  42. data/example/spec/spec_helper.rb +19 -0
  43. data/lib/setty.rb +10 -0
  44. data/lib/setty/loader.rb +50 -0
  45. data/lib/setty/options.rb +15 -0
  46. data/lib/setty/railtie.rb +14 -0
  47. data/lib/setty/version.rb +3 -0
  48. data/setty.gemspec +29 -0
  49. data/spec/fixtures/settings.yml +9 -0
  50. data/spec/fixtures/settings/inner_0.yml +2 -0
  51. data/spec/fixtures/settings/inner_1.yml +2 -0
  52. data/spec/fixtures/settings/inner_1/inner_2/inner_3.yml +2 -0
  53. data/spec/fixtures/settings/inner_empty/.gitkeep +0 -0
  54. data/spec/setty/base_spec.rb +16 -0
  55. data/spec/setty/loader_spec.rb +46 -0
  56. data/spec/setty/options_spec.rb +27 -0
  57. data/spec/spec_helper.rb +13 -0
  58. metadata +214 -0
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ tags
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --colour
2
+ --format=documentation
@@ -0,0 +1,9 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0
5
+ - 2.1
6
+ - jruby-head
7
+ script: bundle exec rspec spec
8
+ notifications:
9
+ email: false
@@ -0,0 +1,5 @@
1
+ # Changelog
2
+
3
+ ## Version 1.0
4
+
5
+ * Initial release
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in setty.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Radoslav Stankov
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,165 @@
1
+ [![Code Climate](https://codeclimate.com/github/RStankov/setty.png)](https://codeclimate.com/github/RStankov/setty)
2
+ [![Build Status](https://secure.travis-ci.org/RStankov/setty.png)](http://travis-ci.org/RStankov/setty)
3
+ [![Code coverage](https://coveralls.io/repos/RStankov/setty/badge.png?branch=master)](https://coveralls.io/r/RStankov/setty)
4
+
5
+ # Setty
6
+
7
+ Mini application configuration for Rails projects.
8
+
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ gem 'setty'
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ ## Usage
21
+
22
+ The config files will be automatically loaded after rails loads.
23
+
24
+ Example:
25
+
26
+ ```
27
+ # config/settings.yml
28
+ production:
29
+ secret_token: "<%= ENV['SECRET_TOKEN'] %>"
30
+ ssl_only: true
31
+
32
+ developement:
33
+ secret_token: "blablablabla"
34
+ ssl_only: false
35
+ ```
36
+
37
+ ```
38
+ # config/settings/products.yml
39
+ production:
40
+ minumum_photos_count: 4
41
+
42
+ development:
43
+ minumum_photos_count: 1
44
+
45
+ test:
46
+ minumum_photos_count: 0
47
+ ```
48
+
49
+ This gives you the `Settings` object:
50
+
51
+ ```Ruby
52
+ # in development
53
+
54
+ Settings.secret_token #=> "blablablabla"
55
+ Settings.secret_token? #=> true
56
+ Settings.ssl_only #=> false
57
+ Settings.ssl_only? #=> false
58
+ Settings.projects.minumum_photos_count #= 1
59
+ ```
60
+
61
+ You can find example of most important features and plugins - [here](https://github.com/RStankov/setty/tree/master/example).
62
+
63
+ ## Features:
64
+
65
+ * Configurable
66
+ * Environment dependent
67
+ * Interpolation
68
+ * Nested settings
69
+
70
+ ### Configurable
71
+
72
+ ```Ruby
73
+ # application.rb
74
+ module MyApp
75
+ class Application < Rails::Application
76
+ # ... code ... code ...
77
+ config.setty.settings_object_name = 'Settings' # => Settings will be loaded in `Settings`
78
+ config.setty.settings_path = 'settings' # => extracts Settings from `config/settings/*` and `config/settings.yml`
79
+ end
80
+ end
81
+ ```
82
+
83
+ ### Environment dependent
84
+
85
+ ```
86
+ # validations.yml
87
+ development:
88
+ require_user_to_belong_to_account: true
89
+
90
+ test:
91
+ require_user_to_belong_to_account: false
92
+
93
+ production:
94
+ require_user_to_belong_to_account: true
95
+ ```
96
+
97
+ Depending on your Rails environment:
98
+
99
+ ```Ruby
100
+ # in development
101
+ Settings::Validations.require_user_to_belong_to_account #=> true
102
+ Settings::Validations.require_user_to_belong_to_account? #=> true
103
+
104
+ # in test
105
+ Settings::Validations.require_user_to_belong_to_account #=> false
106
+ Settings::Validations.require_user_to_belong_to_account? #=> false
107
+ ```
108
+
109
+ ### Interpolation
110
+
111
+ ```
112
+ production:
113
+ archives_path: "<%= Rails.root.join('archives').realpath %>"
114
+ ```
115
+
116
+
117
+ ### Plays nicely with Dotenv
118
+
119
+ ```
120
+ # s3.yml
121
+ production:
122
+ access_key_id: "<%= ENV['S3_ACCESS_KEY'] %>"
123
+ secret_access_key: "<%= ENV['S3_SECRET_KEY'] %>"
124
+ region: "eu-west-1"
125
+ bucket: "my-app"
126
+ ```
127
+
128
+ ```Ruby
129
+ # in production
130
+ Settings::S3.access_key_id #=> S3_ACCESS_KEY from `.env.production`
131
+ Settings::S3.secret_access_key #=> S3_SECRET_KEY from `.env.production`
132
+ ```
133
+
134
+ ### Nested Settings
135
+
136
+ The following yaml files:
137
+
138
+ ```
139
+ config/settings.yml
140
+ config/settings/validations.yml
141
+ config/settings/validations/product.yml
142
+ config/settings/validations/category.yml
143
+ ```
144
+
145
+ Will produce the following settings options hierarchy:
146
+
147
+ ```Ruby
148
+ Settings
149
+ Settings.validations
150
+ Settings.validations.product
151
+ Settings.validations.category
152
+ ```
153
+
154
+ ## Contributing
155
+
156
+ 1. Fork it
157
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
158
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
159
+ 4. Push to the branch (`git push origin my-new-feature`)
160
+ 5. Create new Pull Request
161
+
162
+ ## License
163
+
164
+ **[MIT License](https://github.com/RStankov/setty/blob/master/LICENSE.txt)**
165
+
@@ -0,0 +1,7 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
7
+
@@ -0,0 +1 @@
1
+ S3_SECRET_TOKEN=*********************
@@ -0,0 +1,16 @@
1
+ # See http://help.github.com/ignore-files/ for more about ignoring files.
2
+ #
3
+ # If you find yourself ignoring temporary files generated by your text editor
4
+ # or operating system, you probably want to add a global ignore instead:
5
+ # git config --global core.excludesfile '~/.gitignore_global'
6
+
7
+ # Ignore bundler config.
8
+ /.bundle
9
+
10
+ # Ignore the default SQLite database.
11
+ /db/*.sqlite3
12
+ /db/*.sqlite3-journal
13
+
14
+ # Ignore all logfiles and tempfiles.
15
+ /log/*.log
16
+ /tmp
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,15 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'rails', '4.0.0'
4
+ gem 'sqlite3'
5
+ gem 'sass-rails', '~> 4.0.0'
6
+ gem 'slim'
7
+ gem 'bootstrap-sass'
8
+ gem 'rspec-rails'
9
+ gem 'dotenv-rails'
10
+
11
+ group :development do
12
+ gem 'quiet_assets'
13
+ gem 'thin'
14
+ end
15
+
@@ -0,0 +1,13 @@
1
+ # Setty example Rails application
2
+
3
+ ## Installation
4
+
5
+ ```
6
+ gem install bundler
7
+ bundle install
8
+
9
+ rails server
10
+ ```
11
+
12
+ From there just visit: [localhost:3000/](http://localhost:3000/)
13
+
@@ -0,0 +1,6 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require File.expand_path('../config/application', __FILE__)
5
+
6
+ Example::Application.load_tasks
@@ -0,0 +1,31 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the top of the
9
+ * compiled file, but it's generally better to create a new file per style scope.
10
+ *
11
+ *= require_self
12
+ *= require_tree .
13
+ */
14
+
15
+ @import "reset";
16
+ @import "bootstrap";
17
+
18
+ body { font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 14px; }
19
+
20
+ #example {
21
+ padding: 40px;
22
+ width: 100%;
23
+ min-width: 900px;
24
+
25
+ h1 { font-weight: 500; font-size: 36px; margin-bottom: 20px; }
26
+
27
+ table thead label { color: #428bca; }
28
+ table thead .active { font-weight: bold; color: black; }
29
+ table thead input[type="text"] { padding: 0 6px; width: 99%; }
30
+ table tbody .empty { text-align: center; }
31
+ }
@@ -0,0 +1,43 @@
1
+ html, body, div, span, applet, object, iframe,
2
+ h1, h2, h3, h4, h5, h6, p, blockquote, pre,
3
+ a, abbr, acronym, address, big, cite, code,
4
+ del, dfn, em, img, ins, kbd, q, s, samp,
5
+ small, strike, strong, sub, sup, tt, var,
6
+ b, u, i, center,
7
+ dl, dt, dd, ol, ul, li,
8
+ fieldset, form, label, legend,
9
+ table, caption, tbody, tfoot, thead, tr, th, td,
10
+ article, aside, canvas, details, embed,
11
+ figure, figcaption, footer, header, hgroup,
12
+ menu, nav, output, ruby, section, summary,
13
+ time, mark, audio, video {
14
+ margin: 0;
15
+ padding: 0;
16
+ border: 0;
17
+ font-size: 100%;
18
+ font: inherit;
19
+ vertical-align: baseline;
20
+ }
21
+ /* HTML5 display-role reset for older browsers */
22
+ article, aside, details, figcaption, figure,
23
+ footer, header, hgroup, menu, nav, section {
24
+ display: block;
25
+ }
26
+ body {
27
+ line-height: 1;
28
+ }
29
+ ol, ul {
30
+ list-style: none;
31
+ }
32
+ blockquote, q {
33
+ quotes: none;
34
+ }
35
+ blockquote:before, blockquote:after,
36
+ q:before, q:after {
37
+ content: '';
38
+ content: none;
39
+ }
40
+ table {
41
+ border-collapse: collapse;
42
+ border-spacing: 0;
43
+ }
@@ -0,0 +1,3 @@
1
+ class ApplicationController < ActionController::Base
2
+ protect_from_forgery with: :exception
3
+ end
@@ -0,0 +1,4 @@
1
+ class ExamplesController < ApplicationController
2
+ def index
3
+ end
4
+ end
@@ -0,0 +1,27 @@
1
+ #example
2
+ h1 Settings values
3
+
4
+ table.table.table-striped.table-bordered
5
+ thead
6
+ tr
7
+ th Name
8
+ th Value
9
+ th Description
10
+ tbody
11
+ tr
12
+ td AppSettings.site_name
13
+ td = AppSettings.site_name
14
+ td Settings loaded from root settings file "<i>config/custom_settings.yml</i>"
15
+ tr
16
+ td AppSettings.products.minumum_photos_count
17
+ td = AppSettings.products.minumum_photos_count
18
+ td Nested settings from "<i>config/custom_settings/products</i>"
19
+ tr
20
+ td AppSettings.uploads.s3_secret_token
21
+ td = AppSettings.uploads.s3_secret_token
22
+ td Interpolated Dotenv settings from "<i>config/custom_settings/uploads" (ENV loaded from ".env")
23
+
24
+ tr
25
+ td AppSettings.uploads.s3_active?
26
+ td = AppSettings.uploads.s3_active?
27
+ td Presence checker
@@ -0,0 +1,10 @@
1
+ doctype html
2
+ html
3
+ head
4
+ title Setty example
5
+
6
+ = stylesheet_link_tag 'application', media: 'all'
7
+ = csrf_meta_tags
8
+
9
+ body
10
+ = yield
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
3
+ load Gem.bin_path('bundler', 'bundle')
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
3
+ require_relative '../config/boot'
4
+ require 'rails/commands'
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require_relative '../config/boot'
3
+ require 'rake'
4
+ Rake.application.run
@@ -0,0 +1,4 @@
1
+ # This file is used by Rack-based servers to start the application.
2
+
3
+ require ::File.expand_path('../config/environment', __FILE__)
4
+ run Rails.application
@@ -0,0 +1,21 @@
1
+ require File.expand_path('../boot', __FILE__)
2
+
3
+ require 'rails/all'
4
+
5
+ # Load Setty manually from lib
6
+ $:.unshift File.expand_path('../../../lib', __FILE__)
7
+ require 'setty'
8
+
9
+ # Require the gems listed in Gemfile, including any gems
10
+ # you've limited to :test, :development, or :production.
11
+ Bundler.require(:default, Rails.env)
12
+
13
+ module Example
14
+ class Application < Rails::Application
15
+ # default value is 'settings', it is changed for the example
16
+ config.setty.settings_path = 'custom_settings'
17
+
18
+ # default value is 'AppSettings', it is changed for the example
19
+ config.setty.settings_object_name = 'AppSettings'
20
+ end
21
+ end
@@ -0,0 +1,4 @@
1
+ # Set up gems listed in the Gemfile.
2
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
3
+
4
+ require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
@@ -0,0 +1,7 @@
1
+ development:
2
+ site_name: 'Setty Site Name'
3
+ loaded: true
4
+
5
+ test:
6
+ site_name: 'Bala bla'
7
+ loaded: false
@@ -0,0 +1,5 @@
1
+ development:
2
+ minumum_photos_count: 4
3
+
4
+ test:
5
+ minumum_photos_count: 0
@@ -0,0 +1,6 @@
1
+ development:
2
+ s3_secret_token: "<%= ENV['S3_SECRET_TOKEN'] %>"
3
+ s3_active: false
4
+
5
+ test:
6
+ s3_active: false
@@ -0,0 +1,12 @@
1
+ development:
2
+ adapter: sqlite3
3
+ database: db/development.sqlite3
4
+ pool: 5
5
+ timeout: 5000
6
+
7
+ test:
8
+ adapter: sqlite3
9
+ database: db/test.sqlite3
10
+ pool: 5
11
+ timeout: 5000
12
+
@@ -0,0 +1,5 @@
1
+ # Load the Rails application.
2
+ require File.expand_path('../application', __FILE__)
3
+
4
+ # Initialize the Rails application.
5
+ Example::Application.initialize!
@@ -0,0 +1,29 @@
1
+ Example::Application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb.
3
+
4
+ # In the development environment your application's code is reloaded on
5
+ # every request. This slows down response time but is perfect for development
6
+ # since you don't have to restart the web server when you make code changes.
7
+ config.cache_classes = false
8
+
9
+ # Do not eager load code on boot.
10
+ config.eager_load = false
11
+
12
+ # Show full error reports and disable caching.
13
+ config.consider_all_requests_local = true
14
+ config.action_controller.perform_caching = false
15
+
16
+ # Don't care if the mailer can't send.
17
+ config.action_mailer.raise_delivery_errors = false
18
+
19
+ # Print deprecation notices to the Rails logger.
20
+ config.active_support.deprecation = :log
21
+
22
+ # Raise an error on page load if there are pending migrations
23
+ config.active_record.migration_error = :page_load
24
+
25
+ # Debug mode disables concatenation and preprocessing of assets.
26
+ # This option may cause significant delays in view rendering with a large
27
+ # number of complex assets.
28
+ config.assets.debug = true
29
+ end
@@ -0,0 +1,37 @@
1
+ Example::Application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb.
3
+
4
+ # The test environment is used exclusively to run your application's
5
+ # test suite. You never need to work with it otherwise. Remember that
6
+ # your test database is "scratch space" for the test suite and is wiped
7
+ # and recreated between test runs. Don't rely on the data there!
8
+ config.cache_classes = true
9
+
10
+ # Do not eager load code on boot. This avoids loading your whole application
11
+ # just for the purpose of running a single test. If you are using a tool that
12
+ # preloads Rails for running tests, you may have to set it to true.
13
+ config.eager_load = false
14
+
15
+ # Configure static asset server for tests with Cache-Control for performance.
16
+ config.serve_static_assets = true
17
+ config.static_cache_control = "public, max-age=3600"
18
+
19
+ # Show full error reports and disable caching.
20
+ config.consider_all_requests_local = true
21
+ config.action_controller.perform_caching = false
22
+
23
+ # Raise exceptions instead of rendering exception templates.
24
+ config.action_dispatch.show_exceptions = false
25
+
26
+ # Disable request forgery protection in test environment.
27
+ config.action_controller.allow_forgery_protection = false
28
+
29
+ # Tell Action Mailer not to deliver emails to the real world.
30
+ # The :test delivery method accumulates sent emails in the
31
+ # ActionMailer::Base.deliveries array.
32
+ config.action_mailer.delivery_method = :test
33
+
34
+ # Print deprecation notices to the stderr.
35
+ config.active_support.deprecation = :stderr
36
+ end
37
+
@@ -0,0 +1,12 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Your secret key is used for verifying the integrity of signed cookies.
4
+ # If you change this key, all old signed cookies will become invalid!
5
+
6
+ # Make sure the secret is at least 30 characters and all random,
7
+ # no regular words or you'll be exposed to dictionary attacks.
8
+ # You can use `rake secret` to generate a secure secret key.
9
+
10
+ # Make sure your secret_key_base is kept private
11
+ # if you're sharing your code publicly.
12
+ Example::Application.config.secret_key_base = 'de7dcb2c40f416eb022b006d3156fed75e5398e601c5c9219bde8181cb63d51a330ddca8580fd534038d5d7c69b7d0afa396f5f80538e94275d3e4917c7654e6'
@@ -0,0 +1,3 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ Example::Application.config.session_store :cookie_store, key: '_example_session'
@@ -0,0 +1 @@
1
+ puts "Setty loaded: #{AppSettings.loaded ? 'YES' : 'NO'}"
@@ -0,0 +1,3 @@
1
+ Example::Application.routes.draw do
2
+ root to: 'examples#index'
3
+ end
@@ -0,0 +1,16 @@
1
+ # encoding: UTF-8
2
+ # This file is auto-generated from the current state of the database. Instead
3
+ # of editing this file, please use the migrations feature of Active Record to
4
+ # incrementally modify your database, and then regenerate this schema definition.
5
+ #
6
+ # Note that this schema.rb definition is the authoritative source for your
7
+ # database schema. If you need to create the application database on another
8
+ # system, you should be using db:schema:load, not running all the migrations
9
+ # from scratch. The latter is a flawed and unsustainable approach (the more migrations
10
+ # you'll amass, the slower it'll run and the greater likelihood for issues).
11
+ #
12
+ # It's strongly recommended that you check this file into your version control system.
13
+
14
+ ActiveRecord::Schema.define(version: 0) do
15
+
16
+ end
File without changes
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ describe AppSettings do
4
+ it "has product minimum photos set to 0" do
5
+ expect(AppSettings.products.minumum_photos_count).to eq 0
6
+ end
7
+ end
@@ -0,0 +1,19 @@
1
+ # This file is copied to spec/ when you run 'rails generate rspec:install'
2
+ ENV['RAILS_ENV'] ||= 'test'
3
+
4
+ require File.expand_path("../../config/environment", __FILE__)
5
+ require 'rspec/rails'
6
+ require 'rspec/autorun'
7
+
8
+ # Requires supporting ruby files with custom matchers and macros, etc,
9
+ # in spec/support/ and its subdirectories.
10
+ Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }
11
+
12
+ # Checks for pending migrations before tests are run.
13
+ # If you are not using ActiveRecord, you can remove this line.
14
+ ActiveRecord::Migration.check_pending! if defined?(ActiveRecord::Migration)
15
+
16
+ RSpec.configure do |config|
17
+ config.use_transactional_fixtures = true
18
+ config.infer_base_class_for_anonymous_controllers = false
19
+ end
@@ -0,0 +1,10 @@
1
+ require 'setty/version'
2
+ require 'setty/options'
3
+ require 'setty/loader'
4
+ require 'setty/railtie' if defined? Rails
5
+
6
+ module Setty
7
+ def self.load(path, enviroment)
8
+ Loader.new(path, enviroment).options
9
+ end
10
+ end
@@ -0,0 +1,50 @@
1
+ require 'erb'
2
+ require 'yaml'
3
+ require 'active_support/core_ext/hash/keys.rb'
4
+ require 'active_support/core_ext/string/inflections.rb'
5
+
6
+ module Setty
7
+ MissingEnviromentError = Class.new(RuntimeError)
8
+
9
+ class Loader
10
+ def initialize(path, enviroment)
11
+ @base_path = path
12
+ @enviroment = enviroment
13
+ end
14
+
15
+ def options
16
+ load_options @base_path
17
+ end
18
+
19
+ private
20
+
21
+ def load_options(path)
22
+ options = load_options_from_file "#{path}.yml"
23
+ find_nested_options(path).each do |sub_path|
24
+ options[:"#{File.basename(sub_path)}"] = load_options(sub_path)
25
+ end
26
+ options
27
+ end
28
+
29
+ def find_nested_options(path)
30
+ Dir.glob(File.join(path, '/*')).map { |file_path| "#{path}/#{File.basename(file_path, '.yml')}" }.uniq
31
+ end
32
+
33
+ def load_options_from_file(path)
34
+ enviroment_options = load_enviroment_options_from_file path
35
+
36
+ raise MissingEnviromentError, %Q(Missing "#{@enviroment}" key in #{path}) if enviroment_options.nil?
37
+
38
+ Options[enviroment_options.symbolize_keys]
39
+ end
40
+
41
+ def load_enviroment_options_from_file(path)
42
+ return {} unless File.readable? path
43
+
44
+ yaml_content = ERB.new(File.read(path)).result
45
+ options = YAML.load yaml_content
46
+
47
+ options[@enviroment.to_s]
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,15 @@
1
+ require 'active_support/ordered_options'
2
+ require 'active_support/core_ext/object/blank.rb'
3
+
4
+ module Setty
5
+ class Options < ActiveSupport::OrderedOptions
6
+ def method_missing(name, *args)
7
+ name_string = name.to_s.chomp! '?'
8
+ if name_string
9
+ self[name_string].present?
10
+ else
11
+ super name, *args
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,14 @@
1
+ module Setty
2
+ class Railtie < Rails::Railtie
3
+ config.setty = ActiveSupport::OrderedOptions.new
4
+ config.setty[:settings_path] = 'settings'
5
+ config.setty[:settings_object_name] = 'Settings'
6
+
7
+ initializer 'setty.load' do |app|
8
+ path = app.root.join 'config', app.config.setty[:settings_path]
9
+ object_name = app.config.setty[:settings_object_name]
10
+
11
+ Object.const_set object_name, ::Setty.load(path, Rails.env)
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,3 @@
1
+ module Setty
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'setty/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "setty"
8
+ spec.version = Setty::VERSION
9
+ spec.authors = ["Radoslav Stankov"]
10
+ spec.email = ["rstankov@gmail.com"]
11
+ spec.description = %q{Mini application configuration for Rails projects.}
12
+ spec.summary = %q{Geneartes object hierarchy based on YAML files}
13
+ spec.homepage = "https://github.com/rstankov/setty"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency 'activesupport', '>= 3.2'
22
+
23
+ spec.add_development_dependency 'bundler', '~> 1.3'
24
+ spec.add_development_dependency 'rake'
25
+ spec.add_development_dependency 'rspec', '~> 2.14'
26
+ spec.add_development_dependency 'rspec-mocks', '>= 2.12.3'
27
+ spec.add_development_dependency 'coveralls'
28
+ end
29
+
@@ -0,0 +1,9 @@
1
+ production:
2
+ enviroment: 'production'
3
+ active: false
4
+
5
+ test:
6
+ enviroment: 'test'
7
+ interpolation: <%= 1 + 1 %>
8
+ active: true
9
+
@@ -0,0 +1,2 @@
1
+ test:
2
+ inner: 0
@@ -0,0 +1,2 @@
1
+ test:
2
+ inner: 1
@@ -0,0 +1,2 @@
1
+ test:
2
+ inner: 123
@@ -0,0 +1,16 @@
1
+ require 'spec_helper'
2
+
3
+ describe Setty do
4
+ def fixture(file_name)
5
+ File.expand_path File.join(File.dirname(__FILE__), '..', 'fixtures', file_name)
6
+ end
7
+
8
+ describe "#load" do
9
+ it "returns loaded options" do
10
+ loader = double options: 'options'
11
+ allow(Setty::Loader).to receive(:new).with('path', 'enviroment').and_return loader
12
+
13
+ expect(Setty.load('path', 'enviroment')).to eq 'options'
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,46 @@
1
+ require 'spec_helper'
2
+ require 'tempfile'
3
+
4
+ module Setty
5
+ describe Loader do
6
+ def fixture(file_name)
7
+ File.expand_path File.join(File.dirname(__FILE__), '..', 'fixtures', file_name)
8
+ end
9
+
10
+ it "loads yaml depending on environment variable" do
11
+ options = load 'settings'
12
+ expect(options.enviroment).to eq 'test'
13
+ expect(options.active?).to be_true
14
+ end
15
+
16
+ it "does not complain about missing yaml file" do
17
+ options = load 'non-existing'
18
+ expect(options).to be_empty
19
+ end
20
+
21
+ it "interpolates the yaml content" do
22
+ options = load 'settings'
23
+ expect(options.interpolation).to eq 2
24
+ end
25
+
26
+ it "supports nested settings" do
27
+ options = load 'settings'
28
+ expect(options.inner_0.inner).to eq 0
29
+ expect(options.inner_1.inner).to eq 1
30
+ expect(options.inner_1.inner_2.inner_3.inner).to eq 123
31
+ end
32
+
33
+ it "supports empty nested settings" do
34
+ options = load 'settings'
35
+ expect(options.inner_empty).to eq({})
36
+ end
37
+
38
+ it "raises error on missing environment is settings" do
39
+ expect { load 'settings', 'bongus enviroment' }.to raise_error MissingEnviromentError
40
+ end
41
+
42
+ def load(name, env = 'test')
43
+ Loader.new(fixture(name), env).options
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ module Setty
4
+ describe Options do
5
+ it "has attribute getter" do
6
+ options = Setty::Options[attribute: 'value']
7
+
8
+ expect(options.attribute).to eq 'value'
9
+ expect(options.missing).to be_nil
10
+ end
11
+
12
+ it "has attribute setter (should not be used)" do
13
+ options = Setty::Options.new
14
+ options.attribute = 'value'
15
+
16
+ expect(options.attribute).to eq 'value'
17
+ end
18
+
19
+ it "has attribute checker" do
20
+ options = Setty::Options[active: true, disabled: false]
21
+
22
+ expect(options.active?).to be_true
23
+ expect(options.disabled?).to be_false
24
+ expect(options.missing?).to be_false
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,13 @@
1
+ require 'bundler/setup'
2
+
3
+ if ENV['TRAVIS']
4
+ require 'coveralls'
5
+ Coveralls.wear!
6
+ end
7
+
8
+ require 'setty'
9
+
10
+ RSpec.configure do |config|
11
+ config.expect_with(:rspec) { |c| c.syntax = :expect }
12
+ end
13
+
metadata ADDED
@@ -0,0 +1,214 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: setty
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Radoslav Stankov
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-02-15 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: activesupport
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '3.2'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '3.2'
30
+ - !ruby/object:Gem::Dependency
31
+ name: bundler
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '1.3'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '1.3'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rake
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rspec
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: '2.14'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: '2.14'
78
+ - !ruby/object:Gem::Dependency
79
+ name: rspec-mocks
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: 2.12.3
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: 2.12.3
94
+ - !ruby/object:Gem::Dependency
95
+ name: coveralls
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ description: Mini application configuration for Rails projects.
111
+ email:
112
+ - rstankov@gmail.com
113
+ executables: []
114
+ extensions: []
115
+ extra_rdoc_files: []
116
+ files:
117
+ - .gitignore
118
+ - .rspec
119
+ - .travis.yml
120
+ - CHANGELOG.md
121
+ - Gemfile
122
+ - LICENSE.txt
123
+ - README.md
124
+ - Rakefile
125
+ - example/.env
126
+ - example/.gitignore
127
+ - example/.rspec
128
+ - example/Gemfile
129
+ - example/README.md
130
+ - example/Rakefile
131
+ - example/app/assets/stylesheets/application.css.scss
132
+ - example/app/assets/stylesheets/reset.css
133
+ - example/app/controllers/application_controller.rb
134
+ - example/app/controllers/examples_controller.rb
135
+ - example/app/views/examples/index.html.slim
136
+ - example/app/views/layouts/application.html.slim
137
+ - example/bin/bundle
138
+ - example/bin/rails
139
+ - example/bin/rake
140
+ - example/config.ru
141
+ - example/config/application.rb
142
+ - example/config/boot.rb
143
+ - example/config/custom_settings.yml
144
+ - example/config/custom_settings/products.yml
145
+ - example/config/custom_settings/uploads.yml
146
+ - example/config/database.yml
147
+ - example/config/environment.rb
148
+ - example/config/environments/development.rb
149
+ - example/config/environments/test.rb
150
+ - example/config/initializers/secret_token.rb
151
+ - example/config/initializers/session_store.rb
152
+ - example/config/initializers/setty.rb
153
+ - example/config/routes.rb
154
+ - example/db/schema.rb
155
+ - example/log/.keep
156
+ - example/public/favicon.ico
157
+ - example/spec/features/settings_spec.rb
158
+ - example/spec/spec_helper.rb
159
+ - lib/setty.rb
160
+ - lib/setty/loader.rb
161
+ - lib/setty/options.rb
162
+ - lib/setty/railtie.rb
163
+ - lib/setty/version.rb
164
+ - setty.gemspec
165
+ - spec/fixtures/settings.yml
166
+ - spec/fixtures/settings/inner_0.yml
167
+ - spec/fixtures/settings/inner_1.yml
168
+ - spec/fixtures/settings/inner_1/inner_2/inner_3.yml
169
+ - spec/fixtures/settings/inner_empty/.gitkeep
170
+ - spec/setty/base_spec.rb
171
+ - spec/setty/loader_spec.rb
172
+ - spec/setty/options_spec.rb
173
+ - spec/spec_helper.rb
174
+ homepage: https://github.com/rstankov/setty
175
+ licenses:
176
+ - MIT
177
+ post_install_message:
178
+ rdoc_options: []
179
+ require_paths:
180
+ - lib
181
+ required_ruby_version: !ruby/object:Gem::Requirement
182
+ none: false
183
+ requirements:
184
+ - - ! '>='
185
+ - !ruby/object:Gem::Version
186
+ version: '0'
187
+ segments:
188
+ - 0
189
+ hash: -655774490321426843
190
+ required_rubygems_version: !ruby/object:Gem::Requirement
191
+ none: false
192
+ requirements:
193
+ - - ! '>='
194
+ - !ruby/object:Gem::Version
195
+ version: '0'
196
+ segments:
197
+ - 0
198
+ hash: -655774490321426843
199
+ requirements: []
200
+ rubyforge_project:
201
+ rubygems_version: 1.8.25
202
+ signing_key:
203
+ specification_version: 3
204
+ summary: Geneartes object hierarchy based on YAML files
205
+ test_files:
206
+ - spec/fixtures/settings.yml
207
+ - spec/fixtures/settings/inner_0.yml
208
+ - spec/fixtures/settings/inner_1.yml
209
+ - spec/fixtures/settings/inner_1/inner_2/inner_3.yml
210
+ - spec/fixtures/settings/inner_empty/.gitkeep
211
+ - spec/setty/base_spec.rb
212
+ - spec/setty/loader_spec.rb
213
+ - spec/setty/options_spec.rb
214
+ - spec/spec_helper.rb