yaml_properties 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.
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +39 -0
- data/Rakefile +1 -0
- data/config/properties.yml +0 -0
- data/lib/yaml_properties/version.rb +3 -0
- data/lib/yaml_properties.rb +30 -0
- data/spec/spec_helper.rb +17 -0
- data/spec/test.yml +1 -0
- data/spec/yaml_config_spec.rb +65 -0
- data/yaml_properties.gemspec +33 -0
- metadata +111 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Mark Burns
|
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,39 @@
|
|
1
|
+
# YamlProperties
|
2
|
+
|
3
|
+
If you find yourself often setting app config in yaml files for different
|
4
|
+
environments etc. Then this can be quite useful to simply access those variables.
|
5
|
+
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
YamlProperties.redis_port
|
9
|
+
```
|
10
|
+
|
11
|
+
Will by default read a value from a YAML file in `config/properties.yml`
|
12
|
+
|
13
|
+
```yaml
|
14
|
+
redis_port: 1369
|
15
|
+
```
|
16
|
+
|
17
|
+
Also can be added to a module or class like
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
module Shutl
|
21
|
+
extend YamlProperties
|
22
|
+
end
|
23
|
+
|
24
|
+
```
|
25
|
+
|
26
|
+
#Override filename like this
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
module Shutl
|
30
|
+
extend YamlProperties
|
31
|
+
def self.yaml_file
|
32
|
+
ENV['SINATRA_ENV'] == 'development' ? 'config/properties.yml' : 'config/properties_production.yml'
|
33
|
+
end
|
34
|
+
end
|
35
|
+
```
|
36
|
+
#Yadayada
|
37
|
+
gem 'yaml_config'
|
38
|
+
|
39
|
+
Usual gem/bundler usage/contribution guidelines
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
File without changes
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require "yaml_properties/version"
|
2
|
+
require "active_support/core_ext/hash"
|
3
|
+
|
4
|
+
module YamlProperties
|
5
|
+
def properties
|
6
|
+
@properties ||= load_properties.with_indifferent_access
|
7
|
+
end
|
8
|
+
|
9
|
+
def reset_properties
|
10
|
+
@properties = nil
|
11
|
+
end
|
12
|
+
|
13
|
+
def method_missing(key, *args, &block)
|
14
|
+
return properties[key] if properties.keys.include? key.to_s
|
15
|
+
|
16
|
+
super key, *args, &block
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def yaml_file
|
22
|
+
File.join %w(config properties.yml)
|
23
|
+
end
|
24
|
+
|
25
|
+
def load_properties
|
26
|
+
YAML.load File.open(yaml_file)
|
27
|
+
end
|
28
|
+
|
29
|
+
extend self
|
30
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,17 @@
|
|
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
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
4
|
+
# loaded once.
|
5
|
+
#
|
6
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
7
|
+
RSpec.configure do |config|
|
8
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
9
|
+
config.run_all_when_everything_filtered = true
|
10
|
+
config.filter_run :focus
|
11
|
+
|
12
|
+
# Run specs in random order to surface order dependencies. If you find an
|
13
|
+
# order dependency and want to debug it, you can fix the order by providing
|
14
|
+
# the seed, which is printed after each run.
|
15
|
+
# --seed 1234
|
16
|
+
config.order = 'random'
|
17
|
+
end
|
data/spec/test.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
life_the_universe_and_everything: "Nobody knows"
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require File.expand_path('spec/spec_helper')
|
2
|
+
require './lib/yaml_properties'
|
3
|
+
|
4
|
+
describe YamlProperties do
|
5
|
+
context "in general" do
|
6
|
+
before do
|
7
|
+
File.stub(:open)
|
8
|
+
|
9
|
+
YAML.stub(:load).and_return properties
|
10
|
+
end
|
11
|
+
|
12
|
+
let(:properties) do
|
13
|
+
{
|
14
|
+
"life_the_universe_and_everything" => 42,
|
15
|
+
"some_string_value" => "something",
|
16
|
+
"a boolean" => true,
|
17
|
+
"parent" => {
|
18
|
+
"child"=>"Egg"}
|
19
|
+
}
|
20
|
+
end
|
21
|
+
|
22
|
+
specify do
|
23
|
+
YamlProperties.properties.should == properties
|
24
|
+
end
|
25
|
+
specify do
|
26
|
+
YamlProperties.life_the_universe_and_everything.should == 42
|
27
|
+
end
|
28
|
+
|
29
|
+
specify do
|
30
|
+
YamlProperties.some_string_value.should == "something"
|
31
|
+
end
|
32
|
+
|
33
|
+
specify do
|
34
|
+
YamlProperties.send("a boolean").should == true
|
35
|
+
end
|
36
|
+
|
37
|
+
specify do
|
38
|
+
YamlProperties.parent.should == {"child" => "Egg"}
|
39
|
+
end
|
40
|
+
|
41
|
+
context "extending a module" do
|
42
|
+
module Acme
|
43
|
+
extend YamlProperties
|
44
|
+
end
|
45
|
+
|
46
|
+
specify do
|
47
|
+
Acme.life_the_universe_and_everything.should == 42
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context "overriding yaml_file default" do
|
53
|
+
module Mystery
|
54
|
+
extend YamlProperties
|
55
|
+
|
56
|
+
def self.yaml_file
|
57
|
+
"./spec/test.yml"
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
specify do
|
62
|
+
Mystery.life_the_universe_and_everything.should == "Nobody knows"
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'yaml_properties/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "yaml_properties"
|
8
|
+
gem.version = YamlProperties::VERSION
|
9
|
+
gem.authors = ["Mark Burns"]
|
10
|
+
gem.email = ["markthedeveloper@gmail.com"]
|
11
|
+
gem.description = %q{Easily add configurable variables for app config using YAML files}
|
12
|
+
gem.summary = <<-DESCRIPTION.gsub(/^\s{4}/, '')
|
13
|
+
Example:
|
14
|
+
|
15
|
+
YamlProperties.life_the_universe_and_everything
|
16
|
+
#=> 42
|
17
|
+
|
18
|
+
In config/properties.yml
|
19
|
+
|
20
|
+
life_the_universe_and_everything: 42
|
21
|
+
DESCRIPTION
|
22
|
+
|
23
|
+
gem.homepage = ""
|
24
|
+
|
25
|
+
gem.add_dependency 'active_support'
|
26
|
+
gem.add_development_dependency 'rspec'
|
27
|
+
gem.add_development_dependency 'debugger'
|
28
|
+
|
29
|
+
gem.files = `git ls-files`.split($/)
|
30
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
31
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
32
|
+
gem.require_paths = ["lib"]
|
33
|
+
end
|
metadata
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: yaml_properties
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Mark Burns
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-10-05 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: active_support
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
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: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rspec
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
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: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: debugger
|
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
|
+
description: Easily add configurable variables for app config using YAML files
|
63
|
+
email:
|
64
|
+
- markthedeveloper@gmail.com
|
65
|
+
executables: []
|
66
|
+
extensions: []
|
67
|
+
extra_rdoc_files: []
|
68
|
+
files:
|
69
|
+
- .gitignore
|
70
|
+
- .rspec
|
71
|
+
- Gemfile
|
72
|
+
- LICENSE.txt
|
73
|
+
- README.md
|
74
|
+
- Rakefile
|
75
|
+
- config/properties.yml
|
76
|
+
- lib/yaml_properties.rb
|
77
|
+
- lib/yaml_properties/version.rb
|
78
|
+
- spec/spec_helper.rb
|
79
|
+
- spec/test.yml
|
80
|
+
- spec/yaml_config_spec.rb
|
81
|
+
- yaml_properties.gemspec
|
82
|
+
homepage: ''
|
83
|
+
licenses: []
|
84
|
+
post_install_message:
|
85
|
+
rdoc_options: []
|
86
|
+
require_paths:
|
87
|
+
- lib
|
88
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
|
+
none: false
|
96
|
+
requirements:
|
97
|
+
- - ! '>='
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
requirements: []
|
101
|
+
rubyforge_project:
|
102
|
+
rubygems_version: 1.8.24
|
103
|
+
signing_key:
|
104
|
+
specification_version: 3
|
105
|
+
summary: ! 'Example: YamlProperties.life_the_universe_and_everything #=> 42 In config/properties.yml
|
106
|
+
life_the_universe_and_everything: 42'
|
107
|
+
test_files:
|
108
|
+
- spec/spec_helper.rb
|
109
|
+
- spec/test.yml
|
110
|
+
- spec/yaml_config_spec.rb
|
111
|
+
has_rdoc:
|