egi 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md ADDED
@@ -0,0 +1,11 @@
1
+ # CHANGELOG
2
+
3
+ ## 0.0.2
4
+ * ENHANCEMENT
5
+ * CAP_ENV to set environment and get by Egi.env
6
+
7
+ ## 0.0.1
8
+ * ENHANCEMENT
9
+ * DSL:env for managing multi envs
10
+ * DSL:env can inherit other env
11
+ * DSL:item to declare item
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.0.2
data/lib/egi/env.rb CHANGED
@@ -10,16 +10,16 @@ module Egi
10
10
  items.merge!(Marshal.load(Marshal.dump(Hash[other])))
11
11
  end
12
12
 
13
- def items
14
- @items ||= Hash.new {|hash, key| hash[key] = { :name => key } }
13
+ def group(name = nil, &block)
14
+ items.merge!(Class.new(Group).new(name).instance_eval(&block).items)
15
15
  end
16
16
 
17
- def item(name, hash)
18
- items[name.to_sym].merge!(hash)
17
+ def items
18
+ @items ||= Hash.new {|hash, key| hash[key] = Item[:name => key] }
19
19
  end
20
20
 
21
- def method_missing(name, *args)
22
- items.has_key?(name) ? items[name] : nil
21
+ def item(name, hash)
22
+ items[name.to_sym].update(hash)
23
23
  end
24
24
  end
25
25
  end
data/lib/egi/group.rb ADDED
@@ -0,0 +1,17 @@
1
+ module Egi
2
+ class Group
3
+ def initialize(name = nil)
4
+ @tags = name ? [ name ] : [ ]
5
+ end
6
+
7
+ def items
8
+ @items ||= Hash.new {|hash, key| hash[key] = Item[:name => key, :tags => @tags] }
9
+ end
10
+
11
+ def item(name, hash)
12
+ items[name.to_sym].update(hash)
13
+ self # for method chain
14
+ end
15
+ end
16
+ end
17
+
data/lib/egi/item.rb ADDED
@@ -0,0 +1,16 @@
1
+ module Egi
2
+ class Item < Hash
3
+ def initialize(ifnone = nil, &block)
4
+ super
5
+ self[:tags] ||= []
6
+ end
7
+
8
+ def update(other)
9
+ if tags = other.delete(:tags)
10
+ self[:tags] += Array(tags)
11
+ end
12
+
13
+ super
14
+ end
15
+ end
16
+ end
data/lib/egi/sandbox.rb CHANGED
@@ -13,8 +13,15 @@ module Egi
13
13
  @current_env = name
14
14
 
15
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?
16
+ env = envs[name]
17
+ env.merge!(envs[to_load]) if envs.has_key?(to_load)
18
+ env.instance_eval(&block) if block_given?
19
+
20
+ # define method_missing to access item
21
+ def env.method_missing(name, *args)
22
+ raise MethodMissing if args.size > 0
23
+ items.has_key?(name) ? items[name] : nil
24
+ end
18
25
  end
19
26
 
20
27
  def eval(str)
data/lib/egi.rb CHANGED
@@ -3,6 +3,13 @@ module Egi
3
3
 
4
4
  autoload :Sandbox, 'egi/sandbox'
5
5
  autoload :Env, 'egi/env'
6
+ autoload :Group, 'egi/group'
7
+ autoload :Item, 'egi/item'
8
+
9
+ def env
10
+ name = ENV['EGI_ENV'] || 'default'
11
+ self[name]
12
+ end
6
13
 
7
14
  def [](name)
8
15
  @env.has_key?(name) ? @env[name] : nil
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ klass = Egi::Group
4
+
5
+ describe klass do
6
+ it
7
+ end
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ klass = Egi::Item
4
+
5
+ describe klass do
6
+ it
7
+ end
data/spec/egi_spec.rb CHANGED
@@ -24,6 +24,13 @@ env(:env1) {
24
24
  env(:env2) {
25
25
  item :a, { :hoge => :ugu }
26
26
  }
27
+
28
+ env(:env_group) {
29
+ group(:hoge) {
30
+ item :a, { :hoge => :fuga }
31
+ item :b, { :tags => [ :fuga ] }
32
+ }
33
+ }
27
34
  EOS
28
35
 
29
36
  context "\n#{environments}" do
@@ -44,6 +51,12 @@ env(:env2) {
44
51
  its(:b) { should be_nil }
45
52
  end
46
53
 
54
+ context 'makes env_group' do
55
+ subject { described_class[:env_group] }
56
+ it { should have_item(:a, :hoge => :fuga, :tags => [ :hoge ]) }
57
+ it { should have_item(:b, :tags => [ :hoge, :fuga ]) }
58
+ end
59
+
47
60
  context 'does not make env3' do
48
61
  subject { described_class[:env3] }
49
62
  it { should be_nil }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: egi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-11-22 00:00:00.000000000 Z
12
+ date: 2011-11-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &70035350 !ruby/object:Gem::Requirement
16
+ requirement: &71572070 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70035350
24
+ version_requirements: *71572070
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: autowatchr
27
- requirement: &70035070 !ruby/object:Gem::Requirement
27
+ requirement: &71571750 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70035070
35
+ version_requirements: *71571750
36
36
  description: manage multi-environments
37
37
  email:
38
38
  - okitakunio@gmail.com
@@ -43,6 +43,7 @@ files:
43
43
  - .gitignore
44
44
  - .rspec
45
45
  - .rvmrc
46
+ - CHANGELOG.md
46
47
  - Gemfile
47
48
  - README.md
48
49
  - Rakefile
@@ -50,8 +51,12 @@ files:
50
51
  - egi.gemspec
51
52
  - lib/egi.rb
52
53
  - lib/egi/env.rb
54
+ - lib/egi/group.rb
55
+ - lib/egi/item.rb
53
56
  - lib/egi/sandbox.rb
54
57
  - spec/egi/env_spec.rb
58
+ - spec/egi/group_spec.rb
59
+ - spec/egi/item_spec.rb
55
60
  - spec/egi/sandbox_spec.rb
56
61
  - spec/egi_spec.rb
57
62
  - spec/spec.watchr
@@ -82,6 +87,8 @@ specification_version: 3
82
87
  summary: manage multi-environments
83
88
  test_files:
84
89
  - spec/egi/env_spec.rb
90
+ - spec/egi/group_spec.rb
91
+ - spec/egi/item_spec.rb
85
92
  - spec/egi/sandbox_spec.rb
86
93
  - spec/egi_spec.rb
87
94
  - spec/spec.watchr