canfig 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/canfig/configuration.rb +94 -0
- data/lib/canfig/version.rb +3 -0
- data/lib/canfig.rb +7 -0
- data/spec/spec_helper.rb +99 -0
- metadata +90 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8b19eec0672579cdfc7784d5c0282934e8b77a21
|
4
|
+
data.tar.gz: 1306d93a870c11f3e2ee510d0964a01c0fa9f3ea
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: deba1e2931e74fe4c7a129ecee75e38781e69f91d6dc7e1ced4b33e441d216fa489ca763dc75ff88336e12da1d4e1868e6abfc46865db516d496fbf33ff42454
|
7
|
+
data.tar.gz: a1dd3b1f781976ecd72f09555f1dab265a419d2bc1a169030e11eb03f17b8e8c7ba81e50db73843b49ee58fa9f046af261537c96497a2304e00dd5c47c60c893
|
@@ -0,0 +1,94 @@
|
|
1
|
+
module Canfig
|
2
|
+
class Configuration
|
3
|
+
|
4
|
+
def configure(argh={}, &block)
|
5
|
+
@options ||= {}
|
6
|
+
save_state! do
|
7
|
+
configure_with_args argh
|
8
|
+
configure_with_block &block
|
9
|
+
end
|
10
|
+
self
|
11
|
+
end
|
12
|
+
|
13
|
+
def configure_with_args(argh)
|
14
|
+
save_state! do
|
15
|
+
argh.symbolize_keys.each { |key,val| configure_option(key, val) }
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def configure_with_block(&block)
|
20
|
+
save_state! do
|
21
|
+
instance_eval &block if block_given?
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def configure_option(key, val)
|
26
|
+
raise ArgumentError, "#{key} is not an allowed configuration option" unless @allowed.include?(key)
|
27
|
+
|
28
|
+
save_state! do
|
29
|
+
@changed[key] = [@options[key], val]
|
30
|
+
@options[key] = val
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def changed
|
35
|
+
@changed = {}
|
36
|
+
@options.each { |key,val| @changed[key] = [@saved_state[key], val] if @saved_state[key] != val }
|
37
|
+
@changed
|
38
|
+
end
|
39
|
+
|
40
|
+
def changed?(key)
|
41
|
+
changed.key?(key)
|
42
|
+
end
|
43
|
+
|
44
|
+
def save_state!(&block)
|
45
|
+
if save_state?
|
46
|
+
@saved_state = @options.dup
|
47
|
+
@changed = {}
|
48
|
+
|
49
|
+
if block_given?
|
50
|
+
disable_state_saves!
|
51
|
+
begin
|
52
|
+
yield
|
53
|
+
ensure
|
54
|
+
enable_state_saves!
|
55
|
+
end
|
56
|
+
end
|
57
|
+
else
|
58
|
+
yield if block_given?
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def enable_state_saves!
|
63
|
+
@save_state = true
|
64
|
+
end
|
65
|
+
|
66
|
+
def disable_state_saves!
|
67
|
+
@save_state = false
|
68
|
+
end
|
69
|
+
|
70
|
+
def save_state?
|
71
|
+
@save_state
|
72
|
+
end
|
73
|
+
|
74
|
+
def method_missing(meth, *args, &block)
|
75
|
+
if meth.to_s.match(/=\Z/)
|
76
|
+
opt = meth.to_s.gsub(/=/,'').to_sym
|
77
|
+
return configure_option(opt, args.first) if @allowed.include?(opt)
|
78
|
+
else
|
79
|
+
return @options[meth] if @allowed.include?(meth)
|
80
|
+
end
|
81
|
+
|
82
|
+
super
|
83
|
+
end
|
84
|
+
|
85
|
+
protected
|
86
|
+
|
87
|
+
def initialize(*args, &block)
|
88
|
+
options = args.extract_options!
|
89
|
+
@allowed = options.symbolize_keys.keys
|
90
|
+
enable_state_saves!
|
91
|
+
configure options, &block
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
data/lib/canfig.rb
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
require 'canfig'
|
2
|
+
require 'rspec'
|
3
|
+
require 'coveralls'
|
4
|
+
Coveralls.wear!
|
5
|
+
|
6
|
+
#Dir[File.join(File.dirname(__FILE__), '..', "spec/support/**/*.rb")].each { |f| require f }
|
7
|
+
|
8
|
+
RSpec.configure do |config|
|
9
|
+
#config.before(:suite) do
|
10
|
+
# ActiveRecord::Base.establish_connection adapter: "sqlite3", database: ":memory:"
|
11
|
+
# capture_stdout { load "db/schema.rb" }
|
12
|
+
# load 'support/models.rb'
|
13
|
+
#end
|
14
|
+
|
15
|
+
# rspec-expectations config goes here. You can use an alternate
|
16
|
+
# assertion/expectation library such as wrong or the stdlib/minitest
|
17
|
+
# assertions if you prefer.
|
18
|
+
config.expect_with :rspec do |expectations|
|
19
|
+
# This option will default to `true` in RSpec 4. It makes the `description`
|
20
|
+
# and `failure_message` of custom matchers include text for helper methods
|
21
|
+
# defined using `chain`, e.g.:
|
22
|
+
# be_bigger_than(2).and_smaller_than(4).description
|
23
|
+
# # => "be bigger than 2 and smaller than 4"
|
24
|
+
# ...rather than:
|
25
|
+
# # => "be bigger than 2"
|
26
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
27
|
+
end
|
28
|
+
|
29
|
+
# rspec-mocks config goes here. You can use an alternate test double
|
30
|
+
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
31
|
+
config.mock_with :rspec do |mocks|
|
32
|
+
# Prevents you from mocking or stubbing a method that does not exist on
|
33
|
+
# a real object. This is generally recommended, and will default to
|
34
|
+
# `true` in RSpec 4.
|
35
|
+
mocks.verify_partial_doubles = true
|
36
|
+
end
|
37
|
+
|
38
|
+
# Many RSpec users commonly either run the entire suite or an individual
|
39
|
+
# file, and it's useful to allow more verbose output when running an
|
40
|
+
# individual spec file.
|
41
|
+
if config.files_to_run.one?
|
42
|
+
# Use the documentation formatter for detailed output,
|
43
|
+
# unless a formatter has already been configured
|
44
|
+
# (e.g. via a command-line flag).
|
45
|
+
config.default_formatter = 'doc'
|
46
|
+
end
|
47
|
+
|
48
|
+
# Limits the available syntax to the non-monkey patched syntax that is recommended.
|
49
|
+
# For more details, see:
|
50
|
+
# - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
|
51
|
+
# - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
52
|
+
# - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
|
53
|
+
config.disable_monkey_patching!
|
54
|
+
|
55
|
+
# Run specs in random order to surface order dependencies. If you find an
|
56
|
+
# order dependency and want to debug it, you can fix the order by providing
|
57
|
+
# the seed, which is printed after each run.
|
58
|
+
# --seed 1234
|
59
|
+
config.order = :random
|
60
|
+
|
61
|
+
# Seed global randomization in this process using the `--seed` CLI option.
|
62
|
+
# Setting this allows you to use `--seed` to deterministically reproduce
|
63
|
+
# test failures related to randomization by passing the same `--seed` value
|
64
|
+
# as the one that triggered the failure.
|
65
|
+
Kernel.srand config.seed
|
66
|
+
|
67
|
+
# Print the 10 slowest examples and example groups at the
|
68
|
+
# end of the spec run, to help surface which specs are running
|
69
|
+
# particularly slow.
|
70
|
+
#config.profile_examples = 10
|
71
|
+
|
72
|
+
# These two settings work together to allow you to limit a spec run
|
73
|
+
# to individual examples or groups you care about by tagging them with
|
74
|
+
# `:focus` metadata. When nothing is tagged with `:focus`, all examples
|
75
|
+
# get run.
|
76
|
+
#config.filter_run :focus
|
77
|
+
#config.run_all_when_everything_filtered = true
|
78
|
+
end
|
79
|
+
|
80
|
+
# TODO look into why I need to patch these to work with default behavior?
|
81
|
+
class FalseClass
|
82
|
+
def false?
|
83
|
+
true
|
84
|
+
end
|
85
|
+
|
86
|
+
def true?
|
87
|
+
false
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
class TrueClass
|
92
|
+
def false?
|
93
|
+
false
|
94
|
+
end
|
95
|
+
|
96
|
+
def true?
|
97
|
+
true
|
98
|
+
end
|
99
|
+
end
|
metadata
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: canfig
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mark Rebec
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-05-21 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
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
|
+
description: Dead simple canned configuration for gems or whatever
|
56
|
+
email:
|
57
|
+
- mark@markrebec.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- lib/canfig.rb
|
63
|
+
- lib/canfig/configuration.rb
|
64
|
+
- lib/canfig/version.rb
|
65
|
+
- spec/spec_helper.rb
|
66
|
+
homepage: http://github.com/markrebec/canfig
|
67
|
+
licenses: []
|
68
|
+
metadata: {}
|
69
|
+
post_install_message:
|
70
|
+
rdoc_options: []
|
71
|
+
require_paths:
|
72
|
+
- lib
|
73
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
requirements: []
|
84
|
+
rubyforge_project:
|
85
|
+
rubygems_version: 2.2.2
|
86
|
+
signing_key:
|
87
|
+
specification_version: 4
|
88
|
+
summary: Dead simple canned configuration for gems or whatever
|
89
|
+
test_files:
|
90
|
+
- spec/spec_helper.rb
|