toggle 0.0.0.alpha → 1.0.0.rc
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/.rspec +2 -0
- data/.travis.yml +3 -0
- data/CONTRIBUTING.md +14 -0
- data/Gemfile +1 -1
- data/LICENSE +13 -0
- data/README.md +304 -8
- data/Rakefile +27 -0
- data/bin/toggle +200 -0
- data/defaults/config.yml.default +23 -0
- data/defaults/key.yml.default +15 -0
- data/lib/toggle.rb +76 -3
- data/lib/toggle/compiler.rb +31 -0
- data/lib/toggle/parser.rb +17 -0
- data/lib/toggle/parser/yaml.rb +12 -0
- data/lib/toggle/version.rb +2 -2
- data/script/ci +42 -0
- data/spec/cli_spec.rb +427 -0
- data/spec/parser/yaml_spec.rb +16 -0
- data/spec/parser_spec.rb +39 -0
- data/spec/spec_helper.rb +3 -0
- data/spec/test/fixtures/cli/.gitkeep +0 -0
- data/spec/test/fixtures/config.yml +9 -0
- data/spec/test/fixtures/flat-key-local +1 -0
- data/spec/test/fixtures/key-local.yml +2 -0
- data/spec/toggle_spec.rb +94 -0
- data/toggle.gemspec +15 -11
- metadata +104 -11
- data/LICENSE.txt +0 -22
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'toggle/parser/yaml'
|
3
|
+
|
4
|
+
describe Toggle::Parser::YAML do
|
5
|
+
describe "parse" do
|
6
|
+
let(:parser) { Toggle::Parser::YAML.new }
|
7
|
+
|
8
|
+
it "parses the passed content, converting erb tags" do
|
9
|
+
parser.parse("Hello world <%= 40 + 2 %>").should == "Hello world 42"
|
10
|
+
end
|
11
|
+
|
12
|
+
it "parses the passed content, serializing as yaml" do
|
13
|
+
parser.parse(":hello: world").should == {hello: 'world'}
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/spec/parser_spec.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Toggle::Parser do
|
4
|
+
describe "non-found parser" do
|
5
|
+
it "raises a parser not found error" do
|
6
|
+
lambda {
|
7
|
+
Toggle::Parser.for 'nonexistent-parser'
|
8
|
+
}.should raise_error Toggle::Parser::ParserNotFound
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "'yaml' parser" do
|
13
|
+
it "returns an instance of the Toggle Yaml parser" do
|
14
|
+
parser = Toggle::Parser.for 'yaml'
|
15
|
+
parser.should be_an_instance_of Toggle::Parser::YAML
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "'yml' parser" do
|
20
|
+
it "returns an instance of the Toggle Yaml parser" do
|
21
|
+
parser = Toggle::Parser.for 'yml'
|
22
|
+
parser.should be_an_instance_of Toggle::Parser::YAML
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe ":yaml parser" do
|
27
|
+
it "returns an instance of the Toggle Yaml parser" do
|
28
|
+
parser = Toggle::Parser.for :yaml
|
29
|
+
parser.should be_an_instance_of Toggle::Parser::YAML
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe ":yml parser" do
|
34
|
+
it "returns an instance of the Toggle Yaml parser" do
|
35
|
+
parser = Toggle::Parser.for :yml
|
36
|
+
parser.should be_an_instance_of Toggle::Parser::YAML
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/spec/spec_helper.rb
ADDED
File without changes
|
@@ -0,0 +1,9 @@
|
|
1
|
+
<% @local_erb_attribute_value = 'local_erb_attribute_value' %>
|
2
|
+
<% @remote_erb_attribute_value = 'remote_erb_attribute_value' %>
|
3
|
+
:local:
|
4
|
+
:plain_attribute: local_plain_attribute_value
|
5
|
+
:erb_attribute: <%= @local_erb_attribute_value %>
|
6
|
+
|
7
|
+
:remote:
|
8
|
+
:plain_attribute: remote_plain_attribute_value
|
9
|
+
:erb_attribute: <%= @remote_erb_attribute_value %>
|
@@ -0,0 +1 @@
|
|
1
|
+
local
|
data/spec/toggle_spec.rb
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Toggle do
|
4
|
+
let(:config_filepath) { File.join(FIXTURES_PATH, 'config.yml') }
|
5
|
+
|
6
|
+
describe "#configs" do
|
7
|
+
let(:toggle) { described_class.new config_filepath: config_filepath }
|
8
|
+
|
9
|
+
it "returns compiled content for the specified config file as a hash" do
|
10
|
+
toggle.configs.should == {
|
11
|
+
'local' => {
|
12
|
+
'plain_attribute' => 'local_plain_attribute_value',
|
13
|
+
'erb_attribute' => 'local_erb_attribute_value'
|
14
|
+
},
|
15
|
+
'remote' => {
|
16
|
+
'plain_attribute' => 'remote_plain_attribute_value',
|
17
|
+
'erb_attribute' => 'remote_erb_attribute_value'
|
18
|
+
}
|
19
|
+
}
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "#key" do
|
24
|
+
let(:toggle) { described_class.new }
|
25
|
+
|
26
|
+
it "returns the specified attribute as a symbol" do
|
27
|
+
toggle.key = 'something'
|
28
|
+
toggle.key.should == :something
|
29
|
+
end
|
30
|
+
|
31
|
+
it "returns the flat value when file has no extension" do
|
32
|
+
toggle.key_filepath = File.join(FIXTURES_PATH, 'flat-key-local')
|
33
|
+
toggle.key.should == :local
|
34
|
+
end
|
35
|
+
|
36
|
+
it "returns the compiled key as a symbol from the key file if no key attribute is set" do
|
37
|
+
toggle.key_filepath = File.join(FIXTURES_PATH, 'key-local.yml')
|
38
|
+
toggle.key.should == :local
|
39
|
+
end
|
40
|
+
|
41
|
+
it "returns the set key attribute as a symbol over the compiled key file's key value" do
|
42
|
+
toggle.key = 'something'
|
43
|
+
toggle.key_filepath = File.join(FIXTURES_PATH, 'key-local.yml')
|
44
|
+
toggle.key.should == :something
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe "#config" do
|
49
|
+
let(:toggle) { described_class.new }
|
50
|
+
|
51
|
+
it "returns the config data that corresponds to #key" do
|
52
|
+
toggle.config_filepath = config_filepath
|
53
|
+
toggle.key = :local
|
54
|
+
toggle.config.should == {
|
55
|
+
'plain_attribute' => 'local_plain_attribute_value',
|
56
|
+
'erb_attribute' => 'local_erb_attribute_value'
|
57
|
+
}
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe "#[]" do
|
62
|
+
let(:key) { :local }
|
63
|
+
let(:toggle) { described_class.new config_filepath: config_filepath, key: key }
|
64
|
+
|
65
|
+
it "indifferently returns the value corresponding to the passed argument for the loaded config" do
|
66
|
+
toggle['plain_attribute'].should == 'local_plain_attribute_value'
|
67
|
+
toggle[:plain_attribute].should == 'local_plain_attribute_value'
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
describe "#using" do
|
72
|
+
let(:toggle) { described_class.new config_filepath: config_filepath }
|
73
|
+
|
74
|
+
it "does not raise an exception when a block is not supplied" do
|
75
|
+
lambda {
|
76
|
+
toggle.using(:no_block)
|
77
|
+
}.should_not raise_error
|
78
|
+
end
|
79
|
+
|
80
|
+
it "allows block access to the specified configs data without changing internal state" do
|
81
|
+
toggle.key = :local
|
82
|
+
|
83
|
+
toggle.using(:remote) do |config|
|
84
|
+
config[:plain_attribute].should == 'remote_plain_attribute_value'
|
85
|
+
config[:erb_attribute].should == 'remote_erb_attribute_value'
|
86
|
+
end
|
87
|
+
|
88
|
+
toggle.config.should == {
|
89
|
+
'plain_attribute' => 'local_plain_attribute_value',
|
90
|
+
'erb_attribute' => 'local_erb_attribute_value'
|
91
|
+
}
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
data/toggle.gemspec
CHANGED
@@ -1,19 +1,23 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require 'toggle/version'
|
2
|
+
require File.expand_path('../lib/toggle/version', __FILE__)
|
5
3
|
|
6
4
|
Gem::Specification.new do |gem|
|
7
|
-
gem.name = "toggle"
|
8
|
-
gem.version = Toggle::VERSION
|
9
5
|
gem.authors = ["Jeff Iacono"]
|
10
|
-
gem.email = ["
|
11
|
-
gem.description = %q{
|
12
|
-
gem.summary = %q{
|
13
|
-
gem.homepage = ""
|
6
|
+
gem.email = ["iacono@squareup.com"]
|
7
|
+
gem.description = %q{Easily control and change the path of your script}
|
8
|
+
gem.summary = %q{Easily control and change the path of your script}
|
9
|
+
gem.homepage = "https://github.com/square/toggle"
|
14
10
|
|
15
|
-
gem.files = `git ls-files`.split(
|
16
|
-
gem.executables =
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
17
13
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "toggle"
|
18
15
|
gem.require_paths = ["lib"]
|
16
|
+
gem.version = Toggle::VERSION
|
17
|
+
|
18
|
+
gem.add_runtime_dependency "activesupport", [">= 3.2.3"]
|
19
|
+
|
20
|
+
gem.add_development_dependency "rake"
|
21
|
+
gem.add_development_dependency "cane"
|
22
|
+
gem.add_development_dependency "rspec", [">= 2"]
|
19
23
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: toggle
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.0.0.rc
|
5
5
|
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,24 +9,108 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
13
|
-
dependencies:
|
14
|
-
|
12
|
+
date: 2013-03-14 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: activesupport
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 3.2.3
|
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: 3.2.3
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rake
|
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: cane
|
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
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rspec
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '2'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '2'
|
78
|
+
description: Easily control and change the path of your script
|
15
79
|
email:
|
16
|
-
-
|
17
|
-
executables:
|
80
|
+
- iacono@squareup.com
|
81
|
+
executables:
|
82
|
+
- toggle
|
18
83
|
extensions: []
|
19
84
|
extra_rdoc_files: []
|
20
85
|
files:
|
21
86
|
- .gitignore
|
87
|
+
- .rspec
|
88
|
+
- .travis.yml
|
89
|
+
- CONTRIBUTING.md
|
22
90
|
- Gemfile
|
23
|
-
- LICENSE
|
91
|
+
- LICENSE
|
24
92
|
- README.md
|
25
93
|
- Rakefile
|
94
|
+
- bin/toggle
|
95
|
+
- defaults/config.yml.default
|
96
|
+
- defaults/key.yml.default
|
26
97
|
- lib/toggle.rb
|
98
|
+
- lib/toggle/compiler.rb
|
99
|
+
- lib/toggle/parser.rb
|
100
|
+
- lib/toggle/parser/yaml.rb
|
27
101
|
- lib/toggle/version.rb
|
102
|
+
- script/ci
|
103
|
+
- spec/cli_spec.rb
|
104
|
+
- spec/parser/yaml_spec.rb
|
105
|
+
- spec/parser_spec.rb
|
106
|
+
- spec/spec_helper.rb
|
107
|
+
- spec/test/fixtures/cli/.gitkeep
|
108
|
+
- spec/test/fixtures/config.yml
|
109
|
+
- spec/test/fixtures/flat-key-local
|
110
|
+
- spec/test/fixtures/key-local.yml
|
111
|
+
- spec/toggle_spec.rb
|
28
112
|
- toggle.gemspec
|
29
|
-
homepage:
|
113
|
+
homepage: https://github.com/square/toggle
|
30
114
|
licenses: []
|
31
115
|
post_install_message:
|
32
116
|
rdoc_options: []
|
@@ -46,8 +130,17 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
46
130
|
version: 1.3.1
|
47
131
|
requirements: []
|
48
132
|
rubyforge_project:
|
49
|
-
rubygems_version: 1.8.
|
133
|
+
rubygems_version: 1.8.24
|
50
134
|
signing_key:
|
51
135
|
specification_version: 3
|
52
|
-
summary:
|
53
|
-
test_files:
|
136
|
+
summary: Easily control and change the path of your script
|
137
|
+
test_files:
|
138
|
+
- spec/cli_spec.rb
|
139
|
+
- spec/parser/yaml_spec.rb
|
140
|
+
- spec/parser_spec.rb
|
141
|
+
- spec/spec_helper.rb
|
142
|
+
- spec/test/fixtures/cli/.gitkeep
|
143
|
+
- spec/test/fixtures/config.yml
|
144
|
+
- spec/test/fixtures/flat-key-local
|
145
|
+
- spec/test/fixtures/key-local.yml
|
146
|
+
- spec/toggle_spec.rb
|
data/LICENSE.txt
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
Copyright (c) 2013 Jeff Iacono
|
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.
|