dotcloud 0.0.1 → 0.0.2

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/Gemfile CHANGED
@@ -1,3 +1,3 @@
1
- gem 'activesupport', '~> 3.0.8'
2
- gem 'jeweler', '~> 1.6.2'
1
+ gem 'activesupport', '~> 3.0.0'
2
+ gem 'jeweler', '~> 1.6.0'
3
3
  gem 'i18n', '~> 0.6.0'
data/Rakefile CHANGED
@@ -1,3 +1,6 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+
1
4
  begin
2
5
  require 'jeweler'
3
6
  Jeweler::Tasks.new do |s|
@@ -16,3 +19,12 @@ begin
16
19
  rescue LoadError
17
20
  puts "Jeweler, or one of its dependencies, is not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
18
21
  end
22
+
23
+ task :default => [:test]
24
+
25
+ desc "Run tests"
26
+ Rake::TestTask.new("test") do |t|
27
+ t.pattern = 'test/*_test.rb'
28
+ t.verbose = true
29
+ t.warning = true
30
+ end
data/TODO CHANGED
@@ -1 +1,2 @@
1
- - Add tests
1
+ - Logging
2
+ - More testing
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.0.2
data/lib/dotcloud/dsl.rb CHANGED
@@ -7,6 +7,10 @@ module DotCloud
7
7
  def service(name, &block)
8
8
  @services[name.to_s] = block
9
9
  end
10
+
11
+ def [](name)
12
+ @services[name]
13
+ end
10
14
  end
11
15
 
12
16
  class DSL
@@ -20,19 +24,40 @@ module DotCloud
20
24
  def namespace(name, &block)
21
25
  @current_namespace = Namespace.new
22
26
  @namespaces[name.to_s] = @current_namespace
27
+ yield
28
+ @current_namespace = nil
23
29
  end
30
+ alias_method :application, :namespace
24
31
 
25
32
  def service(name, &block)
33
+ raise ArgumentError, "No current namespace set" unless @current_namespace
26
34
  @current_namespace.service(name, &block)
27
35
  end
36
+
37
+ def run
38
+ namespace_str = Host.instance.namespace
39
+ namespace = @namespaces[namespace_str]
40
+ unless namespace
41
+ puts "No namespace '#{namespace_str}' found"
42
+ return
43
+ end
44
+
45
+ service_str = Host.instance.service
46
+ service = namespace[service_str]
47
+ unless service
48
+ puts "No service '#{service_str}' found in namespace '#{namespace_str}'"
49
+ return
50
+ end
51
+
52
+ service.call
53
+ end
28
54
  end
29
55
  end
30
56
 
57
+
31
58
  def namespace(name, &block)
32
- DSL.instance.namespace(name, &block)
59
+ DotCloud::DSL.instance.namespace(name, &block)
33
60
  end
34
- alias_method :application, :namespace
35
-
36
61
  def service(name, &block)
37
- DSL.instance.service(name, &block)
62
+ DotCloud::DSL.instance.service(name, &block)
38
63
  end
data/lib/dotcloud/host.rb CHANGED
@@ -1,50 +1,60 @@
1
1
  module DotCloud
2
2
  class Host
3
- class << self
4
- def host
5
- do_match
6
- @@host
7
- end
8
- alias_method :str, :host
3
+ include Singleton
9
4
 
10
- def namespace
11
- do_match
12
- @@namespace
13
- end
14
- alias_method :application, :namespace
15
- alias_method :app, :namespace
5
+ def initialize
6
+ reset
7
+ end
16
8
 
17
- def service
18
- do_match
19
- @@service
20
- end
9
+ def reset
10
+ @host = nil
11
+ @namespace = nil
12
+ @service = nil
13
+ @id = nil
14
+ end
21
15
 
22
- def id
23
- do_match
24
- @@id
25
- end
16
+ def host
17
+ do_match unless @host
18
+ @host
19
+ end
20
+ alias_method :str, :host
26
21
 
27
- def type
28
- raise ArgumentError, "TODO: parse dotcloud.yml to get service mappings"
29
- end
22
+ def namespace
23
+ do_match unless @namespace
24
+ @namespace
25
+ end
26
+ alias_method :application, :namespace
27
+ alias_method :app, :namespace
30
28
 
31
- def matched?
32
- class_variable_defined?(:@@namespace)
33
- end
29
+ def service
30
+ do_match unless @service
31
+ @service
32
+ end
34
33
 
35
- private
36
- REGEX = /([a-zA-Z]+)-default-(.*)-([0-9]+)/
37
- def do_match
38
- return if matched?
34
+ def id
35
+ do_match unless @id
36
+ @id
37
+ end
39
38
 
40
- @@host = Socket.gethostname
41
- match = REGEX.match(@@host)
42
- raise ArgumentError, "#{@@host} did not match regex" unless match
39
+ def type
40
+ raise ArgumentError, "TODO: parse dotcloud.yml to get service mappings"
41
+ end
43
42
 
44
- @@namespace = match[1]
45
- @@service = match[2]
46
- @@id = match[3].to_i
43
+ private
44
+ REGEX = /([a-zA-Z]+)-default-(.*)-([0-9]+)/
45
+ def do_match
46
+ @host = Socket.gethostname
47
+ match = REGEX.match(@host)
48
+ unless match
49
+ puts "#{@host} did not match regex"
50
+ return false
47
51
  end
52
+
53
+ @namespace = match[1]
54
+ @service = match[2]
55
+ @id = match[3].to_i
56
+
57
+ true
48
58
  end
49
59
  end
50
60
  end
data/lib/dotcloud.rb CHANGED
@@ -3,9 +3,18 @@ require 'fileutils'
3
3
  require 'socket'
4
4
 
5
5
  # 3rd party includes
6
+ require 'rubygems'
6
7
  require 'active_support'
7
8
 
8
9
  # our files
9
10
  $LOAD_PATH.unshift File.dirname(__FILE__)
10
11
  require 'dotcloud/host'
11
12
  require 'dotcloud/dsl'
13
+
14
+ module DotCloud
15
+ class << self
16
+ def run
17
+ DSL.instance.run
18
+ end
19
+ end
20
+ end
data/test/dsl_test.rb ADDED
@@ -0,0 +1,53 @@
1
+ require 'test/test_helper'
2
+
3
+ class DslTest < Test::Unit::TestCase
4
+ def test_invalid_no_namespace
5
+ assert_raise(ArgumentError) do
6
+ service :foo do
7
+ end
8
+ end
9
+ end
10
+
11
+ def test_few
12
+ @namespace = nil
13
+ @service = nil
14
+
15
+ namespace :na do
16
+ service :sa do
17
+ @namespace = 'na'
18
+ @service = 'sa'
19
+ end
20
+ service :sb do
21
+ @namespace = 'na'
22
+ @service = 'sb'
23
+ end
24
+ end
25
+ namespace :nb do
26
+ service :sx do
27
+ @namespace = 'nb'
28
+ @service = 'sx'
29
+ end
30
+ service :sy do
31
+ @namespace = 'nb'
32
+ @service = 'sy'
33
+ end
34
+ end
35
+
36
+ DotCloud.run
37
+ assert_nil @namespace
38
+ assert_nil @service
39
+
40
+ DotCloud::Host.instance.reset
41
+ DotCloud::Host.instance.send :instance_variable_set, :@namespace, 'na'
42
+ DotCloud.run
43
+ assert_nil @namespace
44
+ assert_nil @service
45
+
46
+ DotCloud::Host.instance.reset
47
+ DotCloud::Host.instance.send :instance_variable_set, :@namespace, 'na'
48
+ DotCloud::Host.instance.send :instance_variable_set, :@service, 'sb'
49
+ DotCloud.run
50
+ assert_equal 'na', @namespace
51
+ assert_equal 'sb', @service
52
+ end
53
+ end
@@ -0,0 +1,3 @@
1
+ require 'test/unit'
2
+
3
+ require File.expand_path('../../lib/dotcloud', __FILE__)
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dotcloud
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Nitay Joffe
@@ -25,12 +25,12 @@ dependencies:
25
25
  requirements:
26
26
  - - ~>
27
27
  - !ruby/object:Gem::Version
28
- hash: 23
28
+ hash: 7
29
29
  segments:
30
30
  - 3
31
31
  - 0
32
- - 8
33
- version: 3.0.8
32
+ - 0
33
+ version: 3.0.0
34
34
  name: activesupport
35
35
  version_requirements: *id001
36
36
  prerelease: false
@@ -41,12 +41,12 @@ dependencies:
41
41
  requirements:
42
42
  - - ~>
43
43
  - !ruby/object:Gem::Version
44
- hash: 11
44
+ hash: 15
45
45
  segments:
46
46
  - 1
47
47
  - 6
48
- - 2
49
- version: 1.6.2
48
+ - 0
49
+ version: 1.6.0
50
50
  name: jeweler
51
51
  version_requirements: *id002
52
52
  prerelease: false
@@ -85,6 +85,8 @@ files:
85
85
  - lib/dotcloud.rb
86
86
  - lib/dotcloud/dsl.rb
87
87
  - lib/dotcloud/host.rb
88
+ - test/dsl_test.rb
89
+ - test/test_helper.rb
88
90
  has_rdoc: true
89
91
  homepage: http://github.com/nitay/dotcloud
90
92
  licenses: []