egi 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 +8 -0
- data/.rspec +2 -0
- data/.rvmrc +1 -0
- data/Gemfile +4 -0
- data/README.md +42 -0
- data/Rakefile +1 -0
- data/VERSION +1 -0
- data/egi.gemspec +29 -0
- data/lib/egi/env.rb +25 -0
- data/lib/egi/sandbox.rb +29 -0
- data/lib/egi.rb +19 -0
- data/spec/egi/env_spec.rb +7 -0
- data/spec/egi/sandbox_spec.rb +9 -0
- data/spec/egi_spec.rb +122 -0
- data/spec/spec.watchr +8 -0
- data/spec/spec_helper.rb +9 -0
- metadata +88 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm gemset use egi
|
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
# egi
|
2
|
+
|
3
|
+
## About egi
|
4
|
+
environment, group, and item
|
5
|
+
|
6
|
+
## USAGE
|
7
|
+
|
8
|
+
% cat egi.conf
|
9
|
+
env(:development) {
|
10
|
+
group(:mysqld) {
|
11
|
+
item :vhost0421, { :tags => [ :master ] }
|
12
|
+
item :vhost0422
|
13
|
+
}
|
14
|
+
|
15
|
+
# you can define item without group
|
16
|
+
item :vhost0423, { :tags => [ :rails ] }
|
17
|
+
}
|
18
|
+
% EGI_ENV=egi irb
|
19
|
+
> require 'egi'
|
20
|
+
> # find by group or tag
|
21
|
+
> Egi.env.mysqld #=> [ { :name => :vhost0421, :tags => [ :mysqld, :master ] },
|
22
|
+
{ :name => :vhost0422, :tags => [ :mysqld ] }
|
23
|
+
]
|
24
|
+
> Egi.env.master #=> [ { :name => :vhost0421, :tags => [ :mysqld, :master ] } ]
|
25
|
+
> # fetch by name
|
26
|
+
> Egi.env.vhost0423 #=> { :name => :vhost0423, :tags => [ :rails ]},
|
27
|
+
|
28
|
+
|
29
|
+
## Syntax
|
30
|
+
|
31
|
+
### env
|
32
|
+
T.B.D
|
33
|
+
|
34
|
+
### group
|
35
|
+
not yet implemented
|
36
|
+
|
37
|
+
### item
|
38
|
+
T.B.D
|
39
|
+
|
40
|
+
## Aliases
|
41
|
+
|
42
|
+
T.B.D
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
data/egi.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "egi"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "egi"
|
7
|
+
s.version = Egi::VERSION
|
8
|
+
s.authors = ["okitan"]
|
9
|
+
s.email = ["okitakunio@gmail.com"]
|
10
|
+
s.homepage = "http://github.com/okitan/egi"
|
11
|
+
s.summary = %q{manage multi-environments}
|
12
|
+
s.description = %q{manage multi-environments}
|
13
|
+
|
14
|
+
s.rubyforge_project = "egi"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
# specify any dependencies here; for example:
|
22
|
+
[ [ 'rspec' ],
|
23
|
+
[ 'autowatchr' ]
|
24
|
+
].each do |gem, version|
|
25
|
+
s.add_development_dependency gem, version
|
26
|
+
end
|
27
|
+
# s.add_development_dependency "rspec"
|
28
|
+
# s.add_runtime_dependency "rest-client"
|
29
|
+
end
|
data/lib/egi/env.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
module Egi
|
2
|
+
class Env
|
3
|
+
def initialize(name)
|
4
|
+
@name = name
|
5
|
+
end
|
6
|
+
|
7
|
+
def merge!(other)
|
8
|
+
other = (other.is_a?(Env) ? other.items : other)
|
9
|
+
# because items has default proc and cannnot dump
|
10
|
+
items.merge!(Marshal.load(Marshal.dump(Hash[other])))
|
11
|
+
end
|
12
|
+
|
13
|
+
def items
|
14
|
+
@items ||= Hash.new {|hash, key| hash[key] = { :name => key } }
|
15
|
+
end
|
16
|
+
|
17
|
+
def item(name, hash)
|
18
|
+
items[name.to_sym].merge!(hash)
|
19
|
+
end
|
20
|
+
|
21
|
+
def method_missing(name, *args)
|
22
|
+
items.has_key?(name) ? items[name] : nil
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/lib/egi/sandbox.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
module Egi
|
2
|
+
class Sandbox
|
3
|
+
def initialize
|
4
|
+
@current_env = :default
|
5
|
+
end
|
6
|
+
|
7
|
+
def envs
|
8
|
+
@envs ||= Hash.new {|hash, key| hash[key] = Env.new(key) }
|
9
|
+
end
|
10
|
+
|
11
|
+
def env(name, opts = {}, &block)
|
12
|
+
name = name.to_sym
|
13
|
+
@current_env = name
|
14
|
+
|
15
|
+
to_load = opts[:load]
|
16
|
+
envs[name].merge!(envs[to_load]) if envs.has_key?(to_load)
|
17
|
+
envs[name].instance_eval(&block) if block_given?
|
18
|
+
end
|
19
|
+
|
20
|
+
def eval(str)
|
21
|
+
instance_eval(str)
|
22
|
+
envs
|
23
|
+
end
|
24
|
+
|
25
|
+
def method_missing(name, *args)
|
26
|
+
envs[@current_env].send(name, *args)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/egi.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
module Egi
|
2
|
+
VERSION = File.read(File.join(File.dirname(__FILE__), %w[ .. VERSION ])).chomp
|
3
|
+
|
4
|
+
autoload :Sandbox, 'egi/sandbox'
|
5
|
+
autoload :Env, 'egi/env'
|
6
|
+
|
7
|
+
def [](name)
|
8
|
+
@env.has_key?(name) ? @env[name] : nil
|
9
|
+
end
|
10
|
+
|
11
|
+
def load(str)
|
12
|
+
@env = Sandbox.new.eval(str)
|
13
|
+
end
|
14
|
+
|
15
|
+
def reset
|
16
|
+
@env = nil
|
17
|
+
end
|
18
|
+
module_function :[], :load, :reset
|
19
|
+
end
|
data/spec/egi_spec.rb
ADDED
@@ -0,0 +1,122 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
klass = Egi
|
4
|
+
|
5
|
+
RSpec::Matchers.define :have_item do |key, value|
|
6
|
+
match do |actual|
|
7
|
+
@actual = actual.__send__(key)
|
8
|
+
expected = { :name => key }.merge(value)
|
9
|
+
@expected = [ expected ]
|
10
|
+
|
11
|
+
@actual == expected
|
12
|
+
end
|
13
|
+
|
14
|
+
diffable
|
15
|
+
end
|
16
|
+
|
17
|
+
describe klass, '.load environments:' do
|
18
|
+
environments = <<-EOS
|
19
|
+
env(:env1) {
|
20
|
+
item :a, { :hoge => :fuga }
|
21
|
+
item :b, { :fuga => :ugu }
|
22
|
+
}
|
23
|
+
|
24
|
+
env(:env2) {
|
25
|
+
item :a, { :hoge => :ugu }
|
26
|
+
}
|
27
|
+
EOS
|
28
|
+
|
29
|
+
context "\n#{environments}" do
|
30
|
+
before(:all) { described_class.load(environments) }
|
31
|
+
after(:all) { described_class.reset }
|
32
|
+
|
33
|
+
context 'makes env1' do
|
34
|
+
subject { described_class[:env1] }
|
35
|
+
|
36
|
+
it { should have_item(:a, :hoge => :fuga) }
|
37
|
+
it { should have_item(:b, :fuga => :ugu) }
|
38
|
+
end
|
39
|
+
|
40
|
+
context 'makes env2' do
|
41
|
+
subject { described_class[:env2] }
|
42
|
+
|
43
|
+
it { should have_item(:a, :hoge => :ugu) }
|
44
|
+
its(:b) { should be_nil }
|
45
|
+
end
|
46
|
+
|
47
|
+
context 'does not make env3' do
|
48
|
+
subject { described_class[:env3] }
|
49
|
+
it { should be_nil }
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe klass, '.load environments:' do
|
55
|
+
environments = <<-EOS
|
56
|
+
env :env1
|
57
|
+
item :a, { :hoge => :fuga }
|
58
|
+
item :b, { :fuga => :ugu }
|
59
|
+
|
60
|
+
env :env2
|
61
|
+
item :a, { :hoge => :ugu }
|
62
|
+
EOS
|
63
|
+
|
64
|
+
context "\n#{environments}" do
|
65
|
+
before(:all) { described_class.load(environments) }
|
66
|
+
after(:all) { described_class.reset }
|
67
|
+
|
68
|
+
context 'makes env1' do
|
69
|
+
subject { described_class[:env1] }
|
70
|
+
|
71
|
+
it { should have_item(:a, :hoge => :fuga) }
|
72
|
+
it { should have_item(:b, :fuga => :ugu) }
|
73
|
+
end
|
74
|
+
|
75
|
+
context 'makes env2' do
|
76
|
+
subject { described_class[:env2] }
|
77
|
+
|
78
|
+
it { should have_item(:a, :hoge => :ugu) }
|
79
|
+
its(:b) { should be_nil }
|
80
|
+
end
|
81
|
+
|
82
|
+
context 'does not make env3' do
|
83
|
+
subject { described_class[:env3] }
|
84
|
+
it { should be_nil }
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
describe klass, '.load environments using load to inherit default:' do
|
90
|
+
environments = <<-EOS
|
91
|
+
env :env1
|
92
|
+
item :a, { :hoge => :fuga }
|
93
|
+
item :b, { :fuga => :ugu }
|
94
|
+
|
95
|
+
env :env2, :load => :env1
|
96
|
+
item :a, { :hoge => :ugu }
|
97
|
+
EOS
|
98
|
+
|
99
|
+
context "\n#{environments}" do
|
100
|
+
before(:all) { described_class.load(environments) }
|
101
|
+
after(:all) { described_class.reset }
|
102
|
+
|
103
|
+
context 'makes env1' do
|
104
|
+
subject { described_class[:env1] }
|
105
|
+
|
106
|
+
it { should have_item(:a, :hoge => :fuga) }
|
107
|
+
it { should have_item(:b, :fuga => :ugu) }
|
108
|
+
end
|
109
|
+
|
110
|
+
context 'makes env2' do
|
111
|
+
subject { described_class[:env2] }
|
112
|
+
|
113
|
+
it { should have_item(:a, :hoge => :ugu) }
|
114
|
+
it { should have_item(:b, :fuga => :ugu) }
|
115
|
+
end
|
116
|
+
|
117
|
+
context 'does not make env3' do
|
118
|
+
subject { described_class[:env3] }
|
119
|
+
it { should be_nil }
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
data/spec/spec.watchr
ADDED
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: egi
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- okitan
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-11-22 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: &70035350 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70035350
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: autowatchr
|
27
|
+
requirement: &70035070 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70035070
|
36
|
+
description: manage multi-environments
|
37
|
+
email:
|
38
|
+
- okitakunio@gmail.com
|
39
|
+
executables: []
|
40
|
+
extensions: []
|
41
|
+
extra_rdoc_files: []
|
42
|
+
files:
|
43
|
+
- .gitignore
|
44
|
+
- .rspec
|
45
|
+
- .rvmrc
|
46
|
+
- Gemfile
|
47
|
+
- README.md
|
48
|
+
- Rakefile
|
49
|
+
- VERSION
|
50
|
+
- egi.gemspec
|
51
|
+
- lib/egi.rb
|
52
|
+
- lib/egi/env.rb
|
53
|
+
- lib/egi/sandbox.rb
|
54
|
+
- spec/egi/env_spec.rb
|
55
|
+
- spec/egi/sandbox_spec.rb
|
56
|
+
- spec/egi_spec.rb
|
57
|
+
- spec/spec.watchr
|
58
|
+
- spec/spec_helper.rb
|
59
|
+
homepage: http://github.com/okitan/egi
|
60
|
+
licenses: []
|
61
|
+
post_install_message:
|
62
|
+
rdoc_options: []
|
63
|
+
require_paths:
|
64
|
+
- lib
|
65
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
67
|
+
requirements:
|
68
|
+
- - ! '>='
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
requirements: []
|
78
|
+
rubyforge_project: egi
|
79
|
+
rubygems_version: 1.8.10
|
80
|
+
signing_key:
|
81
|
+
specification_version: 3
|
82
|
+
summary: manage multi-environments
|
83
|
+
test_files:
|
84
|
+
- spec/egi/env_spec.rb
|
85
|
+
- spec/egi/sandbox_spec.rb
|
86
|
+
- spec/egi_spec.rb
|
87
|
+
- spec/spec.watchr
|
88
|
+
- spec/spec_helper.rb
|