taketo 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. data/Gemfile +1 -1
  2. data/Gemfile.lock +3 -3
  3. data/README.md +20 -7
  4. data/VERSION +1 -1
  5. data/bin/taketo +30 -31
  6. data/features/config.feature +33 -3
  7. data/features/config_validation.feature +29 -4
  8. data/features/connect_to_server.feature +2 -1
  9. data/features/error_handling.feature +1 -0
  10. data/features/help.feature +5 -3
  11. data/features/support/env.rb +2 -0
  12. data/lib/taketo/associated_nodes.rb +90 -0
  13. data/lib/taketo/commands/ssh_command.rb +0 -4
  14. data/lib/taketo/config_printer_visitor.rb +68 -0
  15. data/lib/taketo/config_traverser.rb +55 -0
  16. data/lib/taketo/config_validator.rb +33 -34
  17. data/lib/taketo/config_visitor.rb +29 -0
  18. data/lib/taketo/constructs/base_construct.rb +9 -54
  19. data/lib/taketo/constructs/command.rb +9 -1
  20. data/lib/taketo/constructs/environment.rb +11 -1
  21. data/lib/taketo/constructs/project.rb +5 -0
  22. data/lib/taketo/constructs/server.rb +7 -4
  23. data/lib/taketo/dsl.rb +13 -2
  24. data/lib/taketo/support/named_nodes_collection.rb +10 -0
  25. data/lib/taketo/support.rb +0 -1
  26. data/lib/taketo.rb +2 -1
  27. data/spec/integration/dsl_integration_spec.rb +1 -1
  28. data/spec/lib/taketo/associated_nodes_spec.rb +101 -0
  29. data/spec/lib/taketo/commands/ssh_command_spec.rb +5 -15
  30. data/spec/lib/taketo/config_printer_visitor_spec.rb +112 -0
  31. data/spec/lib/taketo/config_traverser_spec.rb +63 -0
  32. data/spec/lib/taketo/config_validator_spec.rb +53 -39
  33. data/spec/lib/taketo/config_visitor_spec.rb +51 -0
  34. data/spec/lib/taketo/constructs/base_construct_spec.rb +7 -70
  35. data/spec/lib/taketo/constructs/command_spec.rb +20 -8
  36. data/spec/lib/taketo/constructs/config_spec.rb +2 -6
  37. data/spec/lib/taketo/constructs/environment_spec.rb +12 -7
  38. data/spec/lib/taketo/constructs/project_spec.rb +10 -4
  39. data/spec/lib/taketo/constructs/server_spec.rb +25 -16
  40. data/spec/lib/taketo/constructs_factory_spec.rb +12 -12
  41. data/spec/lib/taketo/destination_resolver_spec.rb +32 -32
  42. data/spec/lib/taketo/dsl_spec.rb +115 -98
  43. data/spec/lib/taketo/support/named_nodes_collection_spec.rb +49 -21
  44. data/spec/support/helpers/construct_spec_helper.rb +5 -5
  45. data/spec/support/matchers/be_appropriate_construct_matcher.rb +9 -1
  46. data/spec/support/matchers/have_accessor_matcher.rb +6 -3
  47. metadata +18 -7
  48. data/lib/taketo/config_printer.rb +0 -84
  49. data/lib/taketo/support/eval_delegator.rb +0 -25
  50. data/spec/lib/taketo/config_printer_spec.rb +0 -116
  51. data/spec/lib/taketo/support/eval_delegator_spec.rb +0 -43
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: taketo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-26 00:00:00.000000000 Z
12
+ date: 2012-10-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -75,7 +75,14 @@ dependencies:
75
75
  - - ~>
76
76
  - !ruby/object:Gem::Version
77
77
  version: '0.6'
78
- description:
78
+ description: ! " The aim of the project is to aid quick access to often used servers
79
+ for web-developers\n\n With config similar to the following, one could make his
80
+ life easier:\n\n project :my_project do\n environment :staging do\n server
81
+ do\n host \"192.168.1.1\"\n location \"/var/www/prj1\"\n env
82
+ :TERM => \"xterm-256color\"\n end\n end\n end\n\n put it in ~/.taketo.rc.rb
83
+ (or wherever you want using --config)\n and `taketo my_project` effectively becomes:\n
84
+ \ `ssh -t 192.168.1.1 \"cd /var/www/prj1; TERM=xterm-256color RAILS_ENV=staging
85
+ bash\"`\n\n see http://github.com/v-yarotsky/taketo for additional instructions\n"
79
86
  email: vladimir.yarotksy@gmail.com
80
87
  executables:
81
88
  - taketo
@@ -83,10 +90,13 @@ extensions: []
83
90
  extra_rdoc_files: []
84
91
  files:
85
92
  - bin/taketo
93
+ - lib/taketo/associated_nodes.rb
86
94
  - lib/taketo/commands/ssh_command.rb
87
95
  - lib/taketo/commands.rb
88
- - lib/taketo/config_printer.rb
96
+ - lib/taketo/config_printer_visitor.rb
97
+ - lib/taketo/config_traverser.rb
89
98
  - lib/taketo/config_validator.rb
99
+ - lib/taketo/config_visitor.rb
90
100
  - lib/taketo/constructs/base_construct.rb
91
101
  - lib/taketo/constructs/command.rb
92
102
  - lib/taketo/constructs/config.rb
@@ -97,15 +107,17 @@ files:
97
107
  - lib/taketo/constructs_factory.rb
98
108
  - lib/taketo/destination_resolver.rb
99
109
  - lib/taketo/dsl.rb
100
- - lib/taketo/support/eval_delegator.rb
101
110
  - lib/taketo/support/key_error.rb
102
111
  - lib/taketo/support/named_nodes_collection.rb
103
112
  - lib/taketo/support.rb
104
113
  - lib/taketo.rb
105
114
  - spec/integration/dsl_integration_spec.rb
115
+ - spec/lib/taketo/associated_nodes_spec.rb
106
116
  - spec/lib/taketo/commands/ssh_command_spec.rb
107
- - spec/lib/taketo/config_printer_spec.rb
117
+ - spec/lib/taketo/config_printer_visitor_spec.rb
118
+ - spec/lib/taketo/config_traverser_spec.rb
108
119
  - spec/lib/taketo/config_validator_spec.rb
120
+ - spec/lib/taketo/config_visitor_spec.rb
109
121
  - spec/lib/taketo/constructs/base_construct_spec.rb
110
122
  - spec/lib/taketo/constructs/command_spec.rb
111
123
  - spec/lib/taketo/constructs/config_spec.rb
@@ -115,7 +127,6 @@ files:
115
127
  - spec/lib/taketo/constructs_factory_spec.rb
116
128
  - spec/lib/taketo/destination_resolver_spec.rb
117
129
  - spec/lib/taketo/dsl_spec.rb
118
- - spec/lib/taketo/support/eval_delegator_spec.rb
119
130
  - spec/lib/taketo/support/named_nodes_collection_spec.rb
120
131
  - spec/spec_helper.rb
121
132
  - spec/support/helpers/construct_spec_helper.rb
@@ -1,84 +0,0 @@
1
- module Taketo
2
- class ConfigPrinter
3
- def initialize
4
- @indent_level = 0
5
- @result = ""
6
- end
7
-
8
- def result
9
- @result.chomp
10
- end
11
-
12
- def render(object)
13
- method = "render_#{object.node_type}"
14
- send(method, object)
15
- end
16
-
17
- def render_command(command)
18
- put command.name.to_s + (" - " + command.description if command.description).to_s
19
- result
20
- end
21
-
22
- def render_server(server)
23
- section("Server: #{server.name}") do
24
- put "Host: #{server.host}"
25
- put "Port: #{server.port}" if server.port
26
- put "User: #{server.username}" if server.username
27
- put "Default location: #{server.default_location}" if server.default_location
28
- put "Environment: " + server.environment_variables.map { |n, v| "#{n}=#{v}" }.join(" ")
29
- unless server.commands.empty?
30
- section("Commands:") do
31
- server.commands.each { |c| render_command(c) }
32
- end
33
- end
34
- end
35
- result
36
- end
37
-
38
- def render_environment(environment)
39
- section("Environment: #{environment.name}", ("(No servers)" if environment.servers.empty?)) do
40
- if environment.servers.any?
41
- environment.servers.each { |s| render_server(s) }
42
- end
43
- end
44
- result
45
- end
46
-
47
- def render_project(project)
48
- section("Project: #{project.name}", ("(No environments)" if project.environments.empty?)) do
49
- if project.environments.any?
50
- project.environments.each { |e| render_environment(e) }
51
- end
52
- end
53
- put
54
- result
55
- end
56
-
57
- def render_config(config)
58
- if config.projects.any?
59
- config.projects.each { |p| render_project(p) }
60
-
61
- put
62
- put "Default destination: #{config.default_destination}" if config.default_destination
63
- else
64
- put "There are no projects yet..."
65
- end
66
- result
67
- end
68
-
69
- private
70
-
71
-
72
- def section(title = nil, note = nil)
73
- put [title, note].compact.join(" ") if title
74
- @indent_level += 1
75
- yield
76
- @indent_level -= 1
77
- end
78
-
79
- def put(str = nil)
80
- @result += " " * @indent_level + str.to_s.chomp + "\n"
81
- end
82
- end
83
- end
84
-
@@ -1,25 +0,0 @@
1
- module Taketo
2
- module Support
3
-
4
- ##
5
- # This module allows to use external
6
- # methods in block used by instance_eval,
7
- # that it effectively mimics real closure
8
- #
9
- module EvalDelegator
10
- def evaluate(&block)
11
- @external_self = eval "self", block.binding
12
- self.instance_eval(&block)
13
- end
14
-
15
- def method_missing(method_name, *args, &block)
16
- if @external_self.respond_to?(method_name)
17
- @external_self.send(method_name, *args, &block)
18
- else
19
- super
20
- end
21
- end
22
- end
23
- end
24
- end
25
-
@@ -1,116 +0,0 @@
1
- require File.expand_path('../../../spec_helper', __FILE__)
2
- require 'taketo/config_printer'
3
-
4
- include Taketo
5
-
6
- describe "ConfigPrinter" do
7
- describe "#render" do
8
- it "should render based on node class name" do
9
- construct = stub(:Server, :node_type => :server)
10
- printer.should_receive(:render_server)
11
- printer.render(construct)
12
- end
13
- end
14
-
15
- describe "#render_command" do
16
- let(:command) { stub(:Command, :name => :foo, :description => nil) }
17
-
18
- it "should render command name" do
19
- printer.render_command(command).should == "foo"
20
- end
21
-
22
- it "should also render description if available" do
23
- command.stub(:description => "The description")
24
- printer.render_command(command).should == "foo - The description"
25
- end
26
- end
27
-
28
- describe "#render_server" do
29
- let(:server) do
30
- stub(:Server,
31
- :name => :sponge,
32
- :host => "1.2.3.4",
33
- :port => 8000,
34
- :username => "bob",
35
- :default_location => "/var/app",
36
- :environment_variables => { :FOO => "bar", :BOO => "baz" })
37
- end
38
-
39
- it "should render available server info and commands" do
40
- server.stub(:commands => [:the_command])
41
- printer.should_receive(:render_command).with(:the_command)
42
- printer.render_server(server).should =~
43
- %r[Server: sponge
44
- Host: 1\.2\.3\.4
45
- Port: 8000
46
- User: bob
47
- Default location: /var/app
48
- Environment: (FOO=bar BOO=baz|BOO=baz FOO=bar)
49
- Commands:]
50
- end
51
-
52
- it "should not render commands if there are none" do
53
- server.stub(:commands => [])
54
- printer.render_server(server).should_not include("Commands:")
55
- end
56
- end
57
-
58
- describe "#render_environment" do
59
- let(:environment) do
60
- stub(:Environment,
61
- :name => :foo)
62
- end
63
-
64
- it "should render environment info and servers" do
65
- environment.stub(:servers => [:the_server])
66
- printer.should_receive(:render_server).with(:the_server)
67
- printer.render_environment(environment).should == "Environment: foo"
68
- end
69
-
70
- it "should render appropriate message if there are no servers" do
71
- environment.stub(:servers => [])
72
- printer.render_environment(environment).should == "Environment: foo (No servers)"
73
- end
74
- end
75
-
76
- describe "#render_project" do
77
- let(:project) do
78
- stub(:Project,
79
- :name => :quux)
80
- end
81
-
82
- it "should render project info and it's environments" do
83
- project.stub(:environments => [:the_environment])
84
- printer.should_receive(:render_environment).with(:the_environment)
85
- printer.render_project(project).should == "Project: quux\n"
86
- end
87
-
88
- it "should render appropriate message if there are no environments for project" do
89
- project.stub(:environments => [])
90
- printer.render_project(project).should == "Project: quux (No environments)\n"
91
- end
92
- end
93
-
94
- describe "#render_config" do
95
- let(:config) do
96
- stub(:Config,
97
- :default_destination => "hello:bye")
98
- end
99
-
100
- it "should render default destination and all projects" do
101
- config.stub(:projects => [:the_project])
102
- printer.should_receive(:render_project).with(:the_project)
103
- printer.render_config(config).should == "\nDefault destination: hello:bye"
104
- end
105
-
106
- it "should render appropriate message if there are no projects" do
107
- config.stub(:projects => [])
108
- printer.render_config(config).should == "There are no projects yet..."
109
- end
110
- end
111
-
112
- def printer
113
- @printer ||= ConfigPrinter.new
114
- end
115
- end
116
-
@@ -1,43 +0,0 @@
1
- require File.expand_path('../../../../spec_helper', __FILE__)
2
- require 'taketo/support/eval_delegator'
3
-
4
- class EvalDelegatorContext
5
- include Taketo::Support::EvalDelegator
6
-
7
- def foo
8
- end
9
- end
10
-
11
- describe Taketo::Support::EvalDelegator do
12
- describe "#evaluate" do
13
- it "should execute methods on context if it responds" do
14
- expect do
15
- EvalDelegatorContext.new.evaluate { foo }
16
- end.not_to raise_error
17
- end
18
-
19
- it "should delegate unknown methods to calling context" do
20
- class << self
21
- define_method(:bar) {}
22
- end
23
-
24
- expect do
25
- EvalDelegatorContext.new.evaluate { bar }
26
- end.not_to raise_error
27
- end
28
-
29
- it "should raise if external context does not respond" do
30
- expect do
31
- EvalDelegatorContext.new.evaluate { qux }
32
- end.to raise_error(NameError)
33
- end
34
-
35
- it "should pass local variabnes through the scopes" do
36
- baz = :foo
37
- expect do
38
- EvalDelegatorContext.new.evaluate { baz }
39
- end.not_to raise_error
40
- end
41
- end
42
- end
43
-