dsc 0.0.1

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4787149bb2c2781b6eaccfcb771da5e29b4913a8
4
+ data.tar.gz: 55f0d98a84006955fadce9012671a123c9fee539
5
+ SHA512:
6
+ metadata.gz: b52c5efb4eeaa41935d0e73a9075013156c6a8666076cb235798a87e8f188734414a50cf4dae7313069f114e92372eac5265e63872af682f5887bc6b9bbb0584
7
+ data.tar.gz: 9a4121ba1728cbbd3202255f3754a4dba9984ced97d1392f6f4e516b91042076f6a9a2642dde275923d638309570a4a22de9ec8cd4c6b673b0e5295e553802c0
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
15
+ /bin
16
+ /vendor
17
+ /.rspec
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.1.3
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in dsc.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Wimdu GmbH
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.
data/README.md ADDED
@@ -0,0 +1,52 @@
1
+ # Dead simple configuration
2
+
3
+ Read configuration from a YAML/JSON file and expose the keys as methods.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'dsc'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install dsc
20
+
21
+ ## Usage
22
+
23
+ Create a config file:
24
+
25
+ ```yaml
26
+ development:
27
+ username: dev
28
+ password:
29
+ production:
30
+ username: hugo
31
+ password: secret
32
+ pool: 42
33
+ ```
34
+
35
+ Open the file and use it:
36
+
37
+ ```ruby
38
+ require 'dsc'
39
+
40
+ database_config = Dsc.load_file('config/database.yml', env: 'production')
41
+ database_config.username # => 'hugo'
42
+ ```
43
+
44
+ That's it!
45
+
46
+ ## Contributing
47
+
48
+ 1. Fork it
49
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
50
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
51
+ 4. Push to the branch (`git push origin my-new-feature`)
52
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/dsc.gemspec ADDED
@@ -0,0 +1,26 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'dsc/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "dsc"
7
+ spec.version = Dsc::VERSION
8
+ spec.authors = ["Johannes Barre", "Alexey Fedorov"]
9
+ spec.email = ["johannes.barre@wimdu.com", "alexey.fedorov@wimdu.com"]
10
+ spec.summary = %q{Dead Simple Configuration - made to be used by monkeys}
11
+ spec.description = %q{Read configuration from a YAML/JSON file and expose the keys as methods}
12
+ spec.homepage = "https://github.com/wimdu/dsc"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.required_ruby_version = '>= 2.0'
21
+
22
+ spec.add_dependency "hashie", "~> 3.0"
23
+ spec.add_development_dependency "bundler", "~> 1.7"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "rspec", "~> 3.1"
26
+ end
data/lib/dsc.rb ADDED
@@ -0,0 +1,14 @@
1
+ require "dsc/version"
2
+ require "hashie/mash"
3
+ require "yaml"
4
+ require "dsc/mash"
5
+
6
+ module Dsc
7
+ UndefinedAttribute = Class.new(NoMethodError)
8
+
9
+ def self.load_file(file_path, env: "development")
10
+ config_hash = YAML::load_file(file_path)[env]
11
+
12
+ Dsc::Mash.new(config_hash)
13
+ end
14
+ end
data/lib/dsc/mash.rb ADDED
@@ -0,0 +1,28 @@
1
+ module Dsc
2
+ module Mash
3
+ class << self
4
+ DEFAULT_PROC = lambda do |hash, key|
5
+ raise UndefinedAttribute,
6
+ "Attribute #{key} is not defined in the config file (current hash: #{hash.inspect})."
7
+ end
8
+
9
+ def new(source)
10
+ Hashie::Mash.new(source).tap do |hash|
11
+ recursively_freeze(hash)
12
+ end
13
+ end
14
+
15
+ private
16
+
17
+ def recursively_freeze(object)
18
+ case object
19
+ when Array
20
+ object.each { |obj| recursively_freeze(obj) }
21
+ when Hash
22
+ object.default_proc = DEFAULT_PROC
23
+ recursively_freeze(object.values)
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,3 @@
1
+ module Dsc
2
+ VERSION = "0.0.1"
3
+ end
data/spec/dsc_spec.rb ADDED
@@ -0,0 +1,58 @@
1
+ require "spec_helper"
2
+ require "dsc"
3
+
4
+ RSpec.describe Dsc do
5
+ describe '.load_file' do
6
+ before do
7
+ File.open(config_file, 'w') do |file|
8
+ file.puts <<EOF
9
+ production:
10
+ host: 'http://www.wimdu.com'
11
+ awesome: true
12
+ development:
13
+ host: 'http://example.com'
14
+ stable: false
15
+ number: 42
16
+ array: [1, 2, 3]
17
+ subconfig:
18
+ works: 'aswell'
19
+ EOF
20
+ end
21
+ end
22
+
23
+ subject(:dsc) { Dsc.load_file(config_file, env: env) }
24
+
25
+ let(:config_file) { File.expand_path(__FILE__ + '/../../tmp/config.yml') }
26
+ let(:env) { 'development' }
27
+
28
+ it 'works' do
29
+ expect(dsc).to have_attributes(
30
+ host: 'http://example.com',
31
+ stable: false,
32
+ number: 42,
33
+ array: [1, 2, 3],
34
+ subconfig: {
35
+ works: 'aswell'
36
+ }
37
+ )
38
+ end
39
+
40
+ it "raises an error when trying to access undefined methods" do
41
+ expect { dsc.awesome }.to raise_error(
42
+ Dsc::UndefinedAttribute,
43
+ /awesome is not defined/
44
+ )
45
+ end
46
+
47
+ context 'with env production' do
48
+ let(:env) { 'production' }
49
+
50
+ it 'provides the production stuff' do
51
+ expect(dsc).to have_attributes(
52
+ host: 'http://www.wimdu.com',
53
+ awesome: true
54
+ )
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,89 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # The generated `.rspec` file contains `--require spec_helper` which will cause this
4
+ # file to always be loaded, without a need to explicitly require it in any files.
5
+ #
6
+ # Given that it is always loaded, you are encouraged to keep this file as
7
+ # light-weight as possible. Requiring heavyweight dependencies from this file
8
+ # will add to the boot time of your test suite on EVERY test run, even for an
9
+ # individual file that may not need all of that loaded. Instead, consider making
10
+ # a separate helper file that requires the additional dependencies and performs
11
+ # the additional setup, and require it from the spec files that actually need it.
12
+ #
13
+ # The `.rspec` file also contains a few flags that are not defaults but that
14
+ # users commonly want.
15
+ #
16
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
17
+ RSpec.configure do |config|
18
+ # rspec-expectations config goes here. You can use an alternate
19
+ # assertion/expectation library such as wrong or the stdlib/minitest
20
+ # assertions if you prefer.
21
+ config.expect_with :rspec do |expectations|
22
+ # This option will default to `true` in RSpec 4. It makes the `description`
23
+ # and `failure_message` of custom matchers include text for helper methods
24
+ # defined using `chain`, e.g.:
25
+ # be_bigger_than(2).and_smaller_than(4).description
26
+ # # => "be bigger than 2 and smaller than 4"
27
+ # ...rather than:
28
+ # # => "be bigger than 2"
29
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
30
+ end
31
+
32
+ # rspec-mocks config goes here. You can use an alternate test double
33
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
34
+ config.mock_with :rspec do |mocks|
35
+ # Prevents you from mocking or stubbing a method that does not exist on
36
+ # a real object. This is generally recommended, and will default to
37
+ # `true` in RSpec 4.
38
+ mocks.verify_partial_doubles = true
39
+ end
40
+
41
+ # The settings below are suggested to provide a good initial experience
42
+ # with RSpec, but feel free to customize to your heart's content.
43
+ =begin
44
+ # These two settings work together to allow you to limit a spec run
45
+ # to individual examples or groups you care about by tagging them with
46
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
47
+ # get run.
48
+ config.filter_run :focus
49
+ config.run_all_when_everything_filtered = true
50
+
51
+ # Limits the available syntax to the non-monkey patched syntax that is recommended.
52
+ # For more details, see:
53
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
54
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
55
+ # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
56
+ config.disable_monkey_patching!
57
+
58
+ # This setting enables warnings. It's recommended, but in some cases may
59
+ # be too noisy due to issues in dependencies.
60
+ config.warnings = true
61
+
62
+ # Many RSpec users commonly either run the entire suite or an individual
63
+ # file, and it's useful to allow more verbose output when running an
64
+ # individual spec file.
65
+ if config.files_to_run.one?
66
+ # Use the documentation formatter for detailed output,
67
+ # unless a formatter has already been configured
68
+ # (e.g. via a command-line flag).
69
+ config.default_formatter = 'doc'
70
+ end
71
+
72
+ # Print the 10 slowest examples and example groups at the
73
+ # end of the spec run, to help surface which specs are running
74
+ # particularly slow.
75
+ config.profile_examples = 10
76
+
77
+ # Run specs in random order to surface order dependencies. If you find an
78
+ # order dependency and want to debug it, you can fix the order by providing
79
+ # the seed, which is printed after each run.
80
+ # --seed 1234
81
+ config.order = :random
82
+
83
+ # Seed global randomization in this process using the `--seed` CLI option.
84
+ # Setting this allows you to use `--seed` to deterministically reproduce
85
+ # test failures related to randomization by passing the same `--seed` value
86
+ # as the one that triggered the failure.
87
+ Kernel.srand config.seed
88
+ =end
89
+ end
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dsc
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Johannes Barre
8
+ - Alexey Fedorov
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-10-17 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: hashie
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '3.0'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '3.0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: bundler
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '1.7'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '1.7'
42
+ - !ruby/object:Gem::Dependency
43
+ name: rake
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '10.0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '10.0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: rspec
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: '3.1'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '3.1'
70
+ description: Read configuration from a YAML/JSON file and expose the keys as methods
71
+ email:
72
+ - johannes.barre@wimdu.com
73
+ - alexey.fedorov@wimdu.com
74
+ executables: []
75
+ extensions: []
76
+ extra_rdoc_files: []
77
+ files:
78
+ - ".gitignore"
79
+ - ".ruby-version"
80
+ - Gemfile
81
+ - LICENSE.txt
82
+ - README.md
83
+ - Rakefile
84
+ - dsc.gemspec
85
+ - lib/dsc.rb
86
+ - lib/dsc/mash.rb
87
+ - lib/dsc/version.rb
88
+ - spec/dsc_spec.rb
89
+ - spec/spec_helper.rb
90
+ - tmp/.keep
91
+ homepage: https://github.com/wimdu/dsc
92
+ licenses:
93
+ - MIT
94
+ metadata: {}
95
+ post_install_message:
96
+ rdoc_options: []
97
+ require_paths:
98
+ - lib
99
+ required_ruby_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '2.0'
104
+ required_rubygems_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ requirements: []
110
+ rubyforge_project:
111
+ rubygems_version: 2.2.2
112
+ signing_key:
113
+ specification_version: 4
114
+ summary: Dead Simple Configuration - made to be used by monkeys
115
+ test_files:
116
+ - spec/dsc_spec.rb
117
+ - spec/spec_helper.rb