settingable 0.1.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 44dd382347efa4660d7eb7329684165b25a9326b
4
+ data.tar.gz: 7516072936d6a315e5bbf2322721bf17d39f7e86
5
+ SHA512:
6
+ metadata.gz: 5625c2068e64528122c1fe8d3e927e52a1b431629093c1d079bdb7d4b81fba78dd49a7c517dc6443df8f061f58f087e4bdef8e7656aab0d0abf25d3fde60fd70
7
+ data.tar.gz: 0b8a3f1bf9c29345be135fdee6ec86fc76bd219e79d1132ab035e972d33173e3d2efc9bc901141e53f38a7324afa24f2e7be4e35f9d877ac3331d44ddeba08aa
data/.document ADDED
@@ -0,0 +1,3 @@
1
+ -
2
+ ChangeLog.md
3
+ LICENSE.txt
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ Gemfile.lock
2
+ doc/
3
+ pkg/
4
+ vendor/cache/*.gem
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --colour --format documentation
data/.rubocop.yml ADDED
@@ -0,0 +1,5 @@
1
+ Style/ClassAndModuleChildren:
2
+ Enabled: false
3
+
4
+ Style/StringLiterals:
5
+ EnforcedStyle: double_quotes
data/.yardopts ADDED
@@ -0,0 +1 @@
1
+ --markup markdown --title "settingable Documentation" --protected
data/ChangeLog.md ADDED
@@ -0,0 +1,4 @@
1
+ ### 0.1.0 / 2015-06-25
2
+
3
+ * Initial release:
4
+
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2015 Jeremy Rodi
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,27 @@
1
+ # settingable
2
+
3
+ * [Homepage](https://rubygems.org/gems/settingable)
4
+ * [Documentation](http://rubydoc.info/gems/settingable/frames)
5
+ * [Email](mailto:redjazz96@gmail.com)
6
+
7
+ ## Description
8
+
9
+ TODO: Description
10
+
11
+ ## Features
12
+
13
+ ## Examples
14
+
15
+ require 'settingable'
16
+
17
+ ## Requirements
18
+
19
+ ## Install
20
+
21
+ $ gem install settingable
22
+
23
+ ## Copyright
24
+
25
+ Copyright (c) 2015 Jeremy Rodi
26
+
27
+ See {file:LICENSE.txt} for details.
data/Rakefile ADDED
@@ -0,0 +1,13 @@
1
+ # encoding: utf-8
2
+ # rubocop:disable Style/HashSyntax
3
+ require "rake"
4
+ require "yard"
5
+ require "bundler/gem_tasks"
6
+ require "rspec/core/rake_task"
7
+
8
+ RSpec::Core::RakeTask.new
9
+ YARD::Rake::YardocTask.new
10
+
11
+ task :test => :spec
12
+ task :default => :spec
13
+ task :doc => :yard
@@ -0,0 +1,107 @@
1
+ require "forwardable"
2
+
3
+ module Settingable
4
+ # A module containing the settings configuration.
5
+ module Settings
6
+ # The class methods for the Settings module.
7
+ module ClassMethods
8
+ extend Forwardable
9
+
10
+ def_delegators :settings, :[], :[]=, :fetch,
11
+ :method_missing
12
+ def_delegator :settings, :build, :configure
13
+
14
+ # Returns an instance of the included module. Repeated calls
15
+ # return the same instance.
16
+ #
17
+ # @return [Settings]
18
+ def settings
19
+ @_settings ||= new
20
+ end
21
+
22
+ # @!method default_settings
23
+ # Retrieves the default settings. If there are no defaults,
24
+ # it returns an empty hash.
25
+ #
26
+ # @return [Hash]
27
+ #
28
+ # @!method default_settings(value)
29
+ # Sets the default settings.
30
+ #
31
+ # @param value [Hash] The default settings.
32
+ # @return [void]
33
+ def default_settings(value = nil)
34
+ if value
35
+ @_default_settings = value
36
+ else
37
+ @_default_settings || {}
38
+ end
39
+ end
40
+ end
41
+
42
+ def self.included(base)
43
+ base.extend ClassMethods
44
+ end
45
+
46
+ extend Forwardable
47
+ def_delegators :@settings, :fetch
48
+
49
+ # Initialize the settings. Merges the given settings to the default
50
+ # settings.
51
+ #
52
+ # @param settings [Hash] The initial settings.
53
+ def initialize(settings = {})
54
+ @settings = self.class.default_settings.merge(settings)
55
+ end
56
+
57
+ # Builds the settings construct. It yields itself, and then returns
58
+ # itself.
59
+ #
60
+ # @yield
61
+ # @return [self]
62
+ def build
63
+ yield self
64
+ self
65
+ end
66
+
67
+ # Sets a key to a value.
68
+ #
69
+ # @param key [Symbol, String] The key.
70
+ # @param value [Object] The value.
71
+ # @return [void]
72
+ def []=(key, value)
73
+ @settings[key.to_s.to_sym] = value
74
+ end
75
+
76
+ # Retrieves a key. If it doesn't exist, it errors.
77
+ #
78
+ # @param key [Symbol, String] The key.
79
+ # @return [Object]
80
+ def [](key)
81
+ @settings.fetch(key.to_s.to_sym)
82
+ end
83
+
84
+ # Method missing. For set methods, it maps to the `:[]=` method; for
85
+ # regular methods (i.e. not bang or ? methods), it maps to the `:[]`
86
+ # method.
87
+ #
88
+ # @return [Object]
89
+ def method_missing(method, *args, &block)
90
+ return super if args.length > 1 || block_given? || method =~ /(\?|\!)\z/
91
+ map_method(method, args)
92
+ end
93
+
94
+ private
95
+
96
+ # Maps the methods.
97
+ def map_method(method, args)
98
+ if method =~ /\A(.*)\=\z/ && args.length == 1
99
+ self[$+] = args[0]
100
+ elsif args.length == 0
101
+ self[method.to_s]
102
+ else
103
+ fail NameError, "Undefined method `#{method}' called on #{self}"
104
+ end
105
+ end
106
+ end
107
+ end
@@ -0,0 +1,4 @@
1
+ module Settingable
2
+ # settingable version
3
+ VERSION = "0.1.0"
4
+ end
@@ -0,0 +1,6 @@
1
+ require "settingable/version"
2
+ require "settingable/settings"
3
+
4
+ # Contains the Setting module.
5
+ module Settingable
6
+ end
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require File.expand_path("../lib/settingable/version", __FILE__)
4
+
5
+ Gem::Specification.new do |gem|
6
+ gem.name = "settingable"
7
+ gem.version = Settingable::VERSION
8
+ gem.summary = "Handles configuring your gems."
9
+ gem.description = "Handles configuring your gems."
10
+ gem.license = "MIT"
11
+ gem.authors = ["Jeremy Rodi"]
12
+ gem.email = "redjazz96@gmail.com"
13
+ gem.homepage = "https://github.com/medcat/settingable"
14
+
15
+ gem.files = `git ls-files`.split($RS)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_development_dependency "bundler"
21
+ gem.add_development_dependency "rake"
22
+ gem.add_development_dependency "rspec"
23
+ gem.add_development_dependency "yard"
24
+ end
@@ -0,0 +1,76 @@
1
+ require "spec_helper"
2
+
3
+ # Test module for Setting.
4
+ class Configuration
5
+ def self.reset!
6
+ @_settings = nil
7
+ @_default_settings = nil
8
+ end
9
+
10
+ include Settingable::Settings
11
+ end
12
+
13
+ RSpec.describe Settingable::Settings do
14
+ subject { Configuration.settings }
15
+ before(:each) { Configuration.reset! }
16
+
17
+ it "extends the base" do
18
+ ancestors = (class << Configuration; self; end).ancestors
19
+ expect(ancestors)
20
+ .to include(Settingable::Settings::ClassMethods)
21
+ end
22
+
23
+ describe ".settings" do
24
+ it "returns the same instance" do
25
+ expect(Configuration.settings).to be_a(Configuration)
26
+ expect(Configuration.settings).to be(Configuration.settings)
27
+ end
28
+ end
29
+
30
+ describe ".configure" do
31
+ it "yields itself" do
32
+ expect { |b| Configuration.configure(&b) }.to yield_with_args(subject)
33
+ end
34
+
35
+ it "returns itself" do
36
+ expect(Configuration.configure {}).to be subject
37
+ end
38
+ end
39
+
40
+ describe ".[]" do
41
+ it "maps to the .settings instance" do
42
+ subject[:hello] = "world"
43
+ expect(Configuration[:hello]).to eq "world"
44
+ expect(Configuration[:hello]).to be subject[:hello]
45
+ end
46
+ end
47
+
48
+ describe "#initialize" do
49
+ subject { Configuration.new(settings) }
50
+ let(:settings) { { foo: "bar" }.freeze }
51
+ let(:defaults) { { hello: "world", foo: "baz" }.freeze }
52
+ before(:each) { Configuration.default_settings(defaults) }
53
+
54
+ it "merges instance variables" do
55
+ expect(subject[:hello]).to eq "world"
56
+ expect(subject[:foo]).to eq "bar"
57
+ end
58
+
59
+ it "doesn't modify defaults" do
60
+ subject[:hello] = "you"
61
+ expect(defaults[:hello]).to eq "world"
62
+ end
63
+ end
64
+
65
+ describe "#method_missing" do
66
+ it "maps the correct methods" do
67
+ subject[:hello] = "world"
68
+ expect(subject.hello).to eq("world")
69
+ expect(subject.hello).to be subject[:hello]
70
+
71
+ subject.foo = "bar"
72
+ expect(subject[:foo]).to eq("bar")
73
+ expect(subject[:foo]).to be subject.foo
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,8 @@
1
+ require "spec_helper"
2
+ require "settingable"
3
+
4
+ describe Settingable do
5
+ it "should have a VERSION constant" do
6
+ expect(subject.const_get("VERSION")).to_not be_empty
7
+ end
8
+ end
@@ -0,0 +1,4 @@
1
+ require "rspec"
2
+ require "settingable"
3
+
4
+ include Settingable
metadata ADDED
@@ -0,0 +1,120 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: settingable
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jeremy Rodi
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-06-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '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'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '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'
55
+ - !ruby/object:Gem::Dependency
56
+ name: yard
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Handles configuring your gems.
70
+ email: redjazz96@gmail.com
71
+ executables: []
72
+ extensions: []
73
+ extra_rdoc_files: []
74
+ files:
75
+ - ".document"
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - ".rubocop.yml"
79
+ - ".yardopts"
80
+ - ChangeLog.md
81
+ - Gemfile
82
+ - LICENSE.txt
83
+ - README.md
84
+ - Rakefile
85
+ - lib/settingable.rb
86
+ - lib/settingable/settings.rb
87
+ - lib/settingable/version.rb
88
+ - settingable.gemspec
89
+ - spec/settingable/settings_spec.rb
90
+ - spec/settingable_spec.rb
91
+ - spec/spec_helper.rb
92
+ homepage: https://github.com/medcat/settingable
93
+ licenses:
94
+ - MIT
95
+ metadata: {}
96
+ post_install_message:
97
+ rdoc_options: []
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ requirements: []
111
+ rubyforge_project:
112
+ rubygems_version: 2.4.5
113
+ signing_key:
114
+ specification_version: 4
115
+ summary: Handles configuring your gems.
116
+ test_files:
117
+ - spec/settingable/settings_spec.rb
118
+ - spec/settingable_spec.rb
119
+ - spec/spec_helper.rb
120
+ has_rdoc: