edict 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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9da327f1e5a1f5bd1537f2eaa220ebb072384156
4
+ data.tar.gz: 138b96d579ef6e788d0b11e3881f369fecc5bf3a
5
+ SHA512:
6
+ metadata.gz: e571ab563934cad2d347b74159f77b625c990d927ea82c6a18650e5a1a4c4492187126027a297fadea5c50eea9ff6a78d6dd5779e915296a967a96bde749e62f
7
+ data.tar.gz: 7d2cb031265b90026a37161d57c97893bc900489f79abfd660676678b65674c017b619f0e952968357c5bc349dfd4aebd24f49072d3ded32ebf5583dde13f18a
@@ -0,0 +1,6 @@
1
+ require 'edict/rule'
2
+ require 'edict/command'
3
+ require 'edict/ssh-command'
4
+
5
+ module Edict
6
+ end
@@ -0,0 +1,50 @@
1
+ begin
2
+ require 'caliph'
3
+ require 'edict/rule'
4
+
5
+ module Edict
6
+ class Command < Rule
7
+ include Caliph::CommandLineDSL
8
+
9
+ setting :caliph_shell
10
+ setting :env_hash, {}
11
+ setting :command
12
+
13
+ def self.shell
14
+ @shell ||= Caliph.new
15
+ end
16
+
17
+ def setup
18
+ self.caliph_shell = Edict::Command.shell if field_unset?(:caliph_shell)
19
+ end
20
+
21
+ def build_command
22
+ cmd(*command)
23
+ end
24
+
25
+ def add_env(command)
26
+ env_hash.each_pair do |name, value|
27
+ command.set_env(name, value)
28
+ end
29
+ command
30
+ end
31
+
32
+ def run_command(command)
33
+ caliph_shell.run(command)
34
+ end
35
+
36
+ def check_result(result)
37
+ result.must_succeed!
38
+ end
39
+
40
+ def action
41
+ to_run = build_command
42
+ to_run = add_env(to_run)
43
+ result = run_command(to_run)
44
+ check_result(result)
45
+ end
46
+ end
47
+ end
48
+ rescue LoadError
49
+ # no-op - we don't have Caliph
50
+ end
@@ -0,0 +1,25 @@
1
+ require 'calibrate'
2
+
3
+ module Edict
4
+ class Rule
5
+ include Calibrate::Configurable
6
+ include Calibrate::Configurable::DirectoryStructure
7
+
8
+ def initialize
9
+ setup_defaults
10
+ yield self
11
+ setup
12
+ end
13
+
14
+ def setup
15
+ end
16
+
17
+ def enact
18
+ check_required # from Calibrate
19
+ action
20
+ end
21
+
22
+ def action
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,49 @@
1
+
2
+ begin
3
+ require 'caliph'
4
+ require 'edict/command'
5
+
6
+ module Edict
7
+ class SSHCommand < Command
8
+ setting(:remote_server, nested{
9
+ setting :address
10
+ setting :port, 22
11
+ setting :user, nil
12
+ })
13
+
14
+ setting(:ssh_options, [])
15
+ setting(:verbose, 0)
16
+ nil_fields(:id_file, :free_arguments)
17
+
18
+ def ssh_option(name, value)
19
+ ssh_options << "\"#{name}=#{value}\""
20
+ end
21
+
22
+ def wrap_ssh_around(command_on_remote)
23
+ raise "Empty remote command" if command_on_remote.nil?
24
+ cmd("ssh") do |cmd|
25
+ cmd.options << "-i #{id_file}" if id_file
26
+ cmd.options << "-l #{remote_server.user}" unless remote_server.user.nil?
27
+ cmd.options << remote_server.address
28
+ cmd.options << "-p #{remote_server.port}" #ok
29
+ cmd.options << "-n"
30
+ cmd.options << "-#{'v'*verbose}" if verbose > 0
31
+ unless ssh_options.empty?
32
+ ssh_options.each do |opt|
33
+ cmd.options << "-o #{opt}"
34
+ end
35
+ end
36
+ cmd - escaped_command(command_on_remote)
37
+ end
38
+ end
39
+
40
+ def run_command(command)
41
+ fail "Need remote server for #{self.class.name}" unless remote_server.address
42
+
43
+ super(wrap_ssh_around(command))
44
+ end
45
+ end
46
+ end
47
+ rescue LoadError
48
+ # no Caliph...
49
+ end
@@ -0,0 +1,37 @@
1
+ require 'edict/command'
2
+
3
+ describe Edict::Command do
4
+
5
+ let :mock_shell do
6
+ instance_double(Caliph::Shell)
7
+ end
8
+
9
+ let :test_line do
10
+ %w[a test command]
11
+ end
12
+
13
+ let :command_line do
14
+ instance_double(Caliph::CommandLine)
15
+ end
16
+
17
+ let :result do
18
+ instance_double(Caliph::CommandRunResult)
19
+ end
20
+
21
+ subject :command do
22
+ Edict::Command.new do |test|
23
+ test.env_hash = {:something => :else}
24
+ test.command = test_line
25
+ test.caliph_shell = mock_shell
26
+ end
27
+ end
28
+
29
+ it "should run the command and check output" do
30
+ allow(command).to receive(:cmd).with(*test_line).and_return(command_line)
31
+ expect(command_line).to receive(:set_env).with(:something, :else)
32
+ allow(mock_shell).to receive(:run).with(command_line).and_return(result)
33
+ expect(result).to receive(:must_succeed!)
34
+
35
+ command.enact
36
+ end
37
+ end
@@ -0,0 +1,56 @@
1
+ require 'edict'
2
+
3
+ describe Edict::SSHCommand do
4
+
5
+ let :mock_shell do
6
+ instance_double(Caliph::Shell)
7
+ end
8
+
9
+ let :test_line do
10
+ %w[a test command]
11
+ end
12
+
13
+ let :command_line do
14
+ instance_double(Caliph::CommandLine, "remote command")
15
+ end
16
+
17
+ let :ssh_command_line do
18
+ instance_double(Caliph::CommandLine, "ssh command")
19
+ end
20
+
21
+ let :ssh_options do
22
+ []
23
+ end
24
+
25
+ let :result do
26
+ instance_double(Caliph::CommandRunResult)
27
+ end
28
+
29
+ let :server_address do
30
+ "123.45.67.89"
31
+ end
32
+
33
+ subject :command do
34
+ Edict::SSHCommand.new do |test|
35
+ test.env_hash = {:something => :else}
36
+ test.command = test_line
37
+ test.caliph_shell = mock_shell
38
+ test.remote_server.address = server_address
39
+ end
40
+ end
41
+
42
+ it "should run the command and check output" do
43
+ allow(command).to receive(:cmd).with(*test_line).and_return(command_line)
44
+ allow(command).to receive(:cmd).with("ssh").and_yield(ssh_command_line).and_return(ssh_command_line)
45
+ allow(ssh_command_line).to receive(:options).and_return(ssh_options)
46
+ allow(command).to receive(:escaped_command).and_return(command_line)
47
+ expect(ssh_command_line).to receive(:-).with(command_line)
48
+
49
+ expect(command_line).to receive(:set_env).with(:something, :else)
50
+
51
+ allow(mock_shell).to receive(:run).with(ssh_command_line).and_return(result)
52
+ expect(result).to receive(:must_succeed!)
53
+
54
+ command.enact
55
+ end
56
+ end
@@ -0,0 +1,17 @@
1
+ puts Dir::pwd
2
+ require 'test/unit'
3
+ begin
4
+ require 'spec'
5
+ rescue LoadError
6
+ false
7
+ end
8
+
9
+ class RSpecTest < Test::Unit::TestCase
10
+ def test_that_rspec_is_available
11
+ assert_nothing_raised("\n\n * RSpec isn't available - please run: gem install rspec *\n\n"){ ::Spec }
12
+ end
13
+
14
+ def test_that_specs_pass
15
+ assert(system(*%w{spec -f e -p **/*.rb spec}),"\n\n * Specs failed *\n\n")
16
+ end
17
+ end
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: edict
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Judson Lester
8
+ - Patricia Ho
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2015-09-04 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: calibrate
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">"
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">"
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
28
+ description: |2
29
+ Simple configurable tasks to make things do other things as a rule.
30
+ email:
31
+ - judson@lrdesign.com
32
+ - patricia@lrdesign.com
33
+ executables: []
34
+ extensions: []
35
+ extra_rdoc_files: []
36
+ files:
37
+ - lib/edict.rb
38
+ - lib/edict/command.rb
39
+ - lib/edict/rule.rb
40
+ - lib/edict/ssh-command.rb
41
+ - spec/edict/command_spec.rb
42
+ - spec/edict/ssh-command_spec.rb
43
+ - spec_help/gem_test_suite.rb
44
+ homepage: ''
45
+ licenses:
46
+ - MIT
47
+ metadata: {}
48
+ post_install_message:
49
+ rdoc_options:
50
+ - "--inline-source"
51
+ - "--main"
52
+ - doc/README
53
+ - "--title"
54
+ - edict-0.0.1 Documentation
55
+ require_paths:
56
+ - lib/
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ requirements: []
68
+ rubyforge_project: edict
69
+ rubygems_version: 2.4.8
70
+ signing_key:
71
+ specification_version: 4
72
+ summary: Simple configurable tasks
73
+ test_files:
74
+ - spec_help/gem_test_suite.rb