nifty_settings 1.0.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: afe17f45b901676afd6eda08c0523130f180af55
4
- data.tar.gz: 394d6c9f4fcd34dd355d748e63bc6475ffb68d85
3
+ metadata.gz: c3f19a22952b832a051d656d2180fa939da773dd
4
+ data.tar.gz: f8c9c494f8b908efcb17597444cc4ffccf62da15
5
5
  SHA512:
6
- metadata.gz: 610084ce9b84259a353e11b449d1c41e1233c24d02f30258864d43320abbb1a7df9453ecca6eddd31748f8ddad785f626c578ffd6767dfa8e4bd144e19d991cb
7
- data.tar.gz: 6c5f996ce61be1a6c843bdcdda9b3afd588bfedc807cf98c30bda1a027aa190dcc1193c49883df6259850ef3adea02623ae94790b478923cce5251796044a02b
6
+ metadata.gz: 3d3e5f5bf289e146b78804d4cb939c650f68c1d89de1b7d7da273f0ef49a5bc728cec6716a14bdad9b9b73838bd79ec74d412925db1389b855232a9140b5cbca
7
+ data.tar.gz: 37fcb9282e70ff784af7d76a74d5cbb094410f6159dd7158127ae2ef833031373c0057da2aadb9074a5db3826ad919c2abda4d09dcd7b6aeac01045db907c57a
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.2
4
+ - 1.9.3
5
+ - 2.0.0
6
+ - 2.1.0
7
+ - jruby
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org/'
2
+
3
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,9 @@
1
+ guard 'rspec', cmd: 'bundle exec rspec', failed_mode: :none, all_after_pass: true, all_on_start: true do
2
+ # Specs
3
+ watch(%r(^spec/.+_spec\.rb$))
4
+ watch('spec/spec_helper.rb') { 'spec' }
5
+ watch(%r(^spec/support/(.+)\.rb$)) { 'spec' }
6
+
7
+ # Files
8
+ watch(%r(^lib/(.+)\.rb$)) { |m| "spec/#{m[1]}_spec.rb" }
9
+ end
data/README.md CHANGED
@@ -1 +1,6 @@
1
- # Settings
1
+ # Nifty Settings
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/nifty_settings.png)](http://badge.fury.io/rb/nifty_settings)
4
+ [![Build Status](https://secure.travis-ci.org/krautcomputing/nifty_settings.png)](http://travis-ci.org/krautcomputing/nifty_settings)
5
+ [![Dependency Status](https://gemnasium.com/krautcomputing/nifty_settings.png)](https://gemnasium.com/krautcomputing/nifty_settings)
6
+ [![Code Climate](https://codeclimate.com/github/krautcomputing/nifty_settings.png)](https://codeclimate.com/github/krautcomputing/nifty_settings)
data/Rakefile ADDED
@@ -0,0 +1,5 @@
1
+ require 'rspec/core/rake_task'
2
+
3
+ RSpec::Core::RakeTask.new(:spec)
4
+
5
+ task default: :spec
@@ -5,13 +5,27 @@ require 'erb'
5
5
  module NiftySettings
6
6
  class Settings
7
7
  def initialize(hash = {})
8
- @hash = Hash.new { |h,k| h[k] = self.class.new }
8
+ @hash = Hash.new { |h, k| h[k] = self.class.new }
9
9
  hash.each_pair { |k, v| self[k] = v }
10
10
  end
11
11
 
12
12
  def to_hash
13
13
  unpack_attr @hash
14
14
  end
15
+ alias_method :to_h, :to_hash
16
+
17
+ def to_ary
18
+ self.to_hash.values
19
+ end
20
+ alias_method :to_a, :to_ary
21
+
22
+ def to_s
23
+ if self.nil?
24
+ nil
25
+ else
26
+ self.to_hash
27
+ end.to_s
28
+ end
15
29
 
16
30
  def []=(k, v)
17
31
  @hash[k.to_sym] = normalize_attr(v)
@@ -30,13 +44,10 @@ module NiftySettings
30
44
  has?(key) ? self[key] : default
31
45
  end
32
46
 
33
- def blank?
34
- @hash.blank?
35
- end
36
-
37
- def present?
38
- !blank?
47
+ def empty?
48
+ @hash.empty?
39
49
  end
50
+ alias_method :nil?, :empty?
40
51
 
41
52
  def method_missing(name, *args, &blk)
42
53
  name = name.to_s
@@ -69,15 +80,15 @@ module NiftySettings
69
80
  $stderr.puts "Unable to load settings from #{settings_path} - Please check it exists and is readable."
70
81
  return {}
71
82
  end
72
- if env.nil?
73
- $stderr.puts 'Could not determine environment. If not using Rails, please set RACK_ENV env variable.'
74
- return {}
75
- end
76
83
  # Otherwise, try loading...
77
84
  contents = File.read(settings_path)
78
85
  contents = ERB.new(contents).result
79
86
  contents = YAML.load(contents)
80
- (contents['default'] || {}).deep_merge(contents[env] || {})
87
+ if env.nil?
88
+ contents
89
+ else
90
+ (contents['default'] || {}).deep_merge(contents[env] || {})
91
+ end
81
92
  end
82
93
 
83
94
  def default
@@ -128,7 +139,7 @@ module NiftySettings
128
139
  value.to_hash
129
140
  when Hash
130
141
  Hash.new.tap do |h|
131
- value.each_pair { |k,v| h[k] = unpack_attr(v) }
142
+ value.each_pair { |k, v| h[k] = unpack_attr(v) }
132
143
  end
133
144
  when Array
134
145
  value.map { |v| unpack_attr(v) }
@@ -144,7 +155,7 @@ unless Hash.new.respond_to?(:deep_merge)
144
155
  class Hash
145
156
  def deep_merge(other_hash, &block)
146
157
  self.dup.tap do |this_hash|
147
- other_hash.each_pair do |k,v|
158
+ other_hash.each_pair do |k, v|
148
159
  tv = this_hash[k]
149
160
  if tv.is_a?(Hash) && v.is_a?(Hash)
150
161
  this_hash[k] = tv.deep_merge(v, &block)
@@ -1,3 +1,3 @@
1
1
  module NiftySettings
2
- VERSION = '1.0.1'
2
+ VERSION = '1.1.0'
3
3
  end
@@ -8,7 +8,7 @@ Gem::Specification.new do |gem|
8
8
  gem.version = NiftySettings::VERSION
9
9
  gem.platform = Gem::Platform::RUBY
10
10
  gem.authors = ['Manuel Meurer']
11
- gem.email = 'manuel.meurer@gmail.com'
11
+ gem.email = 'manuel@krautcomputing.com'
12
12
  gem.summary = 'Settings'
13
13
  gem.description = 'Settings'
14
14
  gem.homepage = ''
@@ -18,4 +18,16 @@ Gem::Specification.new do |gem|
18
18
  gem.executables = gem.files.grep(%r(^bin/)).map { |f| File.basename(f) }
19
19
  gem.test_files = gem.files.grep(%r(^(test|spec|features)/))
20
20
  gem.require_paths = ['lib']
21
+
22
+ gem.add_development_dependency 'rake', '>= 0.9.0'
23
+ gem.add_development_dependency 'rspec', '~> 2.14.0'
24
+ gem.add_development_dependency 'rb-fsevent', '~> 0.9.0'
25
+ if RUBY_VERSION < '1.9.3'
26
+ # Use older Guard version that uses older Listen version since
27
+ # Listen >= 2.0.0 only works with Ruby >= 1.9.3
28
+ gem.add_development_dependency 'guard-rspec', '~> 3.1.0'
29
+ gem.add_development_dependency 'listen', '< 2.0.0' if RUBY_VERSION < '1.9.3'
30
+ else
31
+ gem.add_development_dependency 'guard-rspec', '~> 4.2.0'
32
+ end
21
33
  end
@@ -0,0 +1,35 @@
1
+ require 'spec_helper'
2
+
3
+ describe NiftySettings::Settings do
4
+ let(:settings_hash) { { foo: 'bar' } }
5
+ let(:settings) { NiftySettings::Settings.new(settings_hash) }
6
+ let(:empty_settings) { NiftySettings::Settings.new }
7
+
8
+ context 'accessing a setting' do
9
+ context "when it's not present" do
10
+ it 'returns nil' do
11
+ expect(settings.not_found).to be_nil
12
+ end
13
+ end
14
+
15
+ context "when it's present" do
16
+ it 'returns the setting' do
17
+ expect(settings.foo).to eq('bar')
18
+ end
19
+ end
20
+ end
21
+
22
+ describe '#to_s' do
23
+ context 'when no settings are stored' do
24
+ it 'returns an empty string' do
25
+ expect(empty_settings.to_s).to eq('')
26
+ end
27
+ end
28
+
29
+ context 'when settings are stored' do
30
+ it 'returns a string representation of the settings' do
31
+ expect(settings.to_s).to eq(settings_hash.to_s)
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,8 @@
1
+ require 'nifty_settings'
2
+
3
+ RSpec.configure do |config|
4
+ config.treat_symbols_as_metadata_keys_with_true_values = true
5
+ config.run_all_when_everything_filtered = true
6
+ config.filter_run :focus
7
+ config.order = 'random'
8
+ end
metadata CHANGED
@@ -1,28 +1,90 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nifty_settings
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Manuel Meurer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-07-24 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2014-03-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: 0.9.0
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: 0.9.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 2.14.0
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: 2.14.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: rb-fsevent
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: 0.9.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 0.9.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: guard-rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 4.2.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: 4.2.0
13
69
  description: Settings
14
- email: manuel.meurer@gmail.com
70
+ email: manuel@krautcomputing.com
15
71
  executables: []
16
72
  extensions: []
17
73
  extra_rdoc_files: []
18
74
  files:
75
+ - .travis.yml
76
+ - Gemfile
77
+ - Guardfile
19
78
  - LICENSE.txt
20
79
  - README.md
80
+ - Rakefile
21
81
  - lib/nifty_settings.rb
22
82
  - lib/nifty_settings/railtie.rb
23
83
  - lib/nifty_settings/settings.rb
24
84
  - lib/nifty_settings/version.rb
25
85
  - nifty_settings.gemspec
86
+ - spec/nifty_settings/settings_spec.rb
87
+ - spec/spec_helper.rb
26
88
  homepage: ''
27
89
  licenses:
28
90
  - MIT
@@ -43,9 +105,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
43
105
  version: '0'
44
106
  requirements: []
45
107
  rubyforge_project:
46
- rubygems_version: 2.0.2
108
+ rubygems_version: 2.2.2
47
109
  signing_key:
48
110
  specification_version: 4
49
111
  summary: Settings
50
- test_files: []
51
- has_rdoc:
112
+ test_files:
113
+ - spec/nifty_settings/settings_spec.rb
114
+ - spec/spec_helper.rb