traquitana 0.1.0 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
data/lib/config.rb CHANGED
@@ -1,4 +1,4 @@
1
- require "singleton"
1
+ require 'singleton'
2
2
 
3
3
  module Traquitana
4
4
  class Config
@@ -7,7 +7,7 @@ module Traquitana
7
7
 
8
8
  def initialize
9
9
  @configs = {}
10
- @filename = "config/traq.yml"
10
+ @filename = 'config/traq.yml'
11
11
  @target = nil
12
12
  load
13
13
  end
@@ -23,23 +23,22 @@ module Traquitana
23
23
  end
24
24
 
25
25
  def method_missing(meth)
26
- @configs[meth.to_s] || ""
26
+ @configs[meth.to_s] || ''
27
27
  end
28
28
 
29
29
  def setup
30
- STDOUT.puts "Running setup"
30
+ STDOUT.puts 'Running setup'
31
31
 
32
32
  if File.exists?(self.filename)
33
33
  STDERR.puts "The configuration file #{self.filename} already exists."
34
34
  return false
35
35
  end
36
36
 
37
- dir = File.dirname(self.filename)
37
+ dir = File.dirname(filename)
38
38
  Dir.mkdir(dir) if !File.exist?(dir)
39
39
 
40
- STDOUT.puts "Writing #{self.filename}"
41
- File.open(self.filename, "w") do |file|
42
- file << "# Default configuration"
40
+ STDOUT.puts "Writing #{filename}"
41
+ File.open(filename, "w") do |file|
43
42
  file << File.read(self.default)
44
43
  end
45
44
 
@@ -49,6 +48,7 @@ module Traquitana
49
48
  end
50
49
 
51
50
  private
51
+
52
52
  def check_configs(file)
53
53
  @configs = YAML.load(File.read(file || self.filename)) rescue nil
54
54
  STDERR.puts "Configs not found (tried '#{file}' and '#{self.filename}')" if !@configs
data/lib/deployer.rb CHANGED
@@ -1,20 +1,19 @@
1
1
  module Traquitana
2
2
  class Deployer
3
- def initialize(options=nil)
3
+ def initialize(options = nil)
4
4
  @config = Traquitana::Config.instance
5
5
  @verbose = !options.nil? && options[:verbose]
6
- @config.filename = options[:filename] if options[:filename]
6
+ @config.filename = file(options)
7
7
  @config.target = options[:target] if options[:target]
8
8
  end
9
9
 
10
10
  def run
11
11
  STDOUT.puts "\e[1mRunning Traquitana version #{VERSION}\e[0m\n\n"
12
- Traquitana::Migrator.new.run
13
12
 
14
- if !File.exist?(@config.filename)
15
- STDERR.puts "\e[31mNo config file (#{@config.filename}) found."
16
- STDERR.puts "Did you run \e[1mtraq setup\e[0;31m ?"
17
- STDERR.puts "Run it and check the configuration before deploying.\e[0m"
13
+ unless File.exist?(@config.filename)
14
+ warn "\e[31mNo config file (#{@config.filename}) found."
15
+ warn "Did you run \e[1mtraq setup\e[0;31m ?"
16
+ warn "Run it and check the configuration before deploying.\e[0m"
18
17
  exit 1
19
18
  end
20
19
 
@@ -30,7 +29,7 @@ module Traquitana
30
29
  all_list_file, all_list_zip = @packager.pack
31
30
 
32
31
  if !File.exists?(all_list_file) || !File.exists?(all_list_zip)
33
- STDERR.puts "\e[31mCould not create the needed files.\e[0m"
32
+ warn "\e[31mCould not create the needed files.\e[0m"
34
33
  exit 2
35
34
  end
36
35
 
@@ -59,5 +58,13 @@ module Traquitana
59
58
  File.unlink(all_list_zip)
60
59
  STDOUT.puts "\e[32mAll done. Have fun.\e[0m\n"
61
60
  end
61
+
62
+ private
63
+
64
+ def file(options)
65
+ return options[:filename] if options[:filename]
66
+
67
+ @config.filename
68
+ end
62
69
  end
63
70
  end
data/lib/packager.rb CHANGED
@@ -1,14 +1,14 @@
1
- require "tmpdir"
2
- require "zip"
1
+ require 'tmpdir'
2
+ require 'zip'
3
3
 
4
4
  module Traquitana
5
5
  class Packager
6
6
  attr_reader :id
7
7
  attr_accessor :verbose
8
8
 
9
- def initialize(dir = "")
9
+ def initialize(dir = '')
10
10
  @dir = dir
11
- @id = Time.now.strftime("%Y%m%d%H%M%S%L")
11
+ @id = Time.now.strftime('%Y%m%d%H%M%S%L')
12
12
  @verbose = verbose
13
13
  end
14
14
 
@@ -21,24 +21,30 @@ module Traquitana
21
21
  end
22
22
 
23
23
  def pack
24
- list_path = "#{Dir.tmpdir}/#{self.list_file}"
25
- zip_path = "#{Dir.tmpdir}/#{self.zip_file}"
26
- list = Traquitana::Selector.new(@dir).files
27
- regex = @dir.to_s.size < 1 ? "" : Regexp.new("^#{@dir}")
24
+ list_path = "#{Dir.tmpdir}/#{self.list_file}"
25
+ zip_path = "#{Dir.tmpdir}/#{self.zip_file}"
26
+ list = Traquitana::Selector.new(@dir).files
27
+ regex = @dir.to_s.size < 1 ? '' : Regexp.new("^#{@dir}")
28
28
 
29
29
  # write list file
30
30
  STDOUT.puts "Creating the list file: #{list_path}" if @verbose
31
- File.open(list_path, "w") {|file| file << list.map { |f| f.sub(regex,"") }.join("\n") }
31
+
32
+ File.open(list_path, 'w') do |file|
33
+ file << list.map do |f|
34
+ f.sub(regex, '')
35
+ end.join("\n")
36
+ end
32
37
 
33
38
  # write zip file
34
39
  STDOUT.puts "Creating the zip file : #{zip_path}" if @verbose
35
- Zip::File.open(zip_path, "w") do |zip_file|
40
+
41
+ Zip::File.open(zip_path, 'w') do |zip_file|
36
42
  for file in list
37
- strip = file.sub(regex, "")
43
+ strip = file.sub(regex, '')
38
44
  zip_file.add(strip, file)
39
45
  end
40
46
  end
41
- [ list_path, zip_path ]
47
+ [list_path, zip_path]
42
48
  end
43
49
  end
44
50
  end
data/lib/selector.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module Traquitana
2
2
  class Selector
3
- def initialize(dir = "")
3
+ def initialize(dir = '')
4
4
  @dir = dir
5
5
  end
6
6
 
data/lib/ssh.rb CHANGED
@@ -33,7 +33,7 @@ module Traquitana
33
33
  channel.send_data("#{pwd}\n")
34
34
  sleep 0.1
35
35
  else
36
- puts msg if msg.size > 1
36
+ STDOUT.puts msg if msg.size > 1
37
37
  end
38
38
  chd.wait
39
39
  end
data/lib/traquitana.rb CHANGED
@@ -1,3 +1,3 @@
1
- %w(traquitana/version config selector deployer packager ssh bar migrator cleaner).each do |file|
1
+ %w(traquitana/version config selector deployer packager ssh bar cleaner).each do |file|
2
2
  require File.dirname(__FILE__)+"/"+file
3
3
  end
@@ -1,3 +1,3 @@
1
1
  module Traquitana
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.5"
3
3
  end
data/spec/bar_spec.rb CHANGED
@@ -1,45 +1,52 @@
1
- require "minitest/autorun"
1
+ require 'minitest/autorun'
2
2
  require "#{File.expand_path(File.dirname(__FILE__))}/../lib/traquitana.rb"
3
3
 
4
4
  describe Traquitana::Bar do
5
- before do
6
- @bar = Traquitana::Bar.new
7
- @bar.total = 100
8
- end
9
-
10
- describe "limits" do
11
- it "should have a total" do
12
- @bar.must_respond_to :total
13
- end
14
- it "should have a current value" do
15
- @bar.must_respond_to :current
16
- end
17
- end
18
-
19
- describe "updates" do
20
- it "should have a name" do
21
- @bar.must_respond_to :name
22
- end
23
- it "should have a update method" do
24
- @bar.must_respond_to :update
25
- end
26
- it "should have a indicator method" do
27
- @bar.must_respond_to :indicator
28
- end
29
- it "should return the correct string for 0%" do
30
- @bar.indicator(0).must_equal "____________________"
31
- end
32
- it "should return the correct string for 25%" do
33
- @bar.indicator(25).must_equal "#####_______________"
34
- end
35
- it "should return the correct string for 50%" do
36
- @bar.indicator(50).must_equal "##########__________"
37
- end
38
- it "should return the correct string for 75%" do
39
- @bar.indicator(75).must_equal "###############_____"
40
- end
41
- it "should return the correct string for 100%" do
42
- @bar.indicator(100).must_equal "####################"
43
- end
44
- end
5
+ before do
6
+ @bar = Traquitana::Bar.new
7
+ @bar.total = 100
8
+ end
9
+
10
+ describe 'limits' do
11
+ it 'should have a total' do
12
+ expect(@bar).must_respond_to :total
13
+ end
14
+ it 'should have a current value' do
15
+ expect(@bar).must_respond_to :current
16
+ end
17
+ end
18
+
19
+ describe 'updates' do
20
+ it 'should have a name' do
21
+ expect(@bar).must_respond_to :name
22
+ end
23
+
24
+ it 'should have a update method' do
25
+ expect(@bar).must_respond_to :update
26
+ end
27
+
28
+ it 'should have a indicator method' do
29
+ expect(@bar).must_respond_to :indicator
30
+ end
31
+
32
+ it 'should return the correct string for 0%' do
33
+ expect(@bar.indicator(0)).must_equal '____________________'
34
+ end
35
+
36
+ it 'should return the correct string for 25%' do
37
+ expect(@bar.indicator(25)).must_equal '#####_______________'
38
+ end
39
+
40
+ it 'should return the correct string for 50%' do
41
+ expect(@bar.indicator(50)).must_equal '##########__________'
42
+ end
43
+
44
+ it 'should return the correct string for 75%' do
45
+ expect(@bar.indicator(75)).must_equal '###############_____'
46
+ end
47
+
48
+ it 'should return the correct string for 100%' do
49
+ expect(@bar.indicator(100)).must_equal '####################'
50
+ end
51
+ end
45
52
  end
data/spec/cleaner_spec.rb CHANGED
@@ -1,22 +1,23 @@
1
- require "minitest/autorun"
1
+ require 'minitest/autorun'
2
+ require 'minitest/focus'
2
3
  require "#{File.expand_path(File.dirname(__FILE__))}/../lib/traquitana.rb"
3
4
 
4
5
  describe Traquitana::Cleaner do
5
- before do
6
- @cleaner = Traquitana::Cleaner.new
7
- @config = Traquitana::Config.instance
8
- @config.load
9
- end
6
+ before do
7
+ @cleaner = Traquitana::Cleaner.new
8
+ @config = Traquitana::Config.instance
9
+ @config.load
10
+ end
10
11
 
11
- it "should have a run method" do
12
- @cleaner.must_respond_to :run
13
- end
12
+ it 'should have a run method' do
13
+ expect(@cleaner).must_respond_to :run
14
+ end
14
15
 
15
- it "should run cleaner on remote host" do
16
- network = MiniTest::Mock.new
17
- network.expect(:execute,nil,[["find #{@config.directory}/traq -type f -iname '*.zip' -o -iname '*.list' | sort | head -n-2 | xargs rm $1"]])
18
- @cleaner.network = network
19
- @cleaner.run
20
- network.verify
21
- end
16
+ it 'should run cleaner on remote host' do
17
+ network = MiniTest::Mock.new
18
+ network.expect(:execute, nil, [["find #{@config.directory}/traq -type f -iname '*.zip' -o -iname '*.list' | sort | head -n-2 | xargs rm $1"]])
19
+ @cleaner.network = network
20
+ @cleaner.run
21
+ network.verify
22
+ end
22
23
  end
data/spec/config/Gemfile CHANGED
@@ -1,3 +1,6 @@
1
1
  source 'http://rubygems.org'
2
2
 
3
+ ruby '2.7.2'
4
+
3
5
  gem 'memoize'
6
+ gem 'rake'
data/spec/config/Rakefile CHANGED
@@ -0,0 +1,11 @@
1
+ namespace 'db' do
2
+ task :migrate do
3
+ STDOUT.puts "running migrations ..."
4
+ end
5
+ end
6
+
7
+ namespace 'assets' do
8
+ task :precompile do
9
+ STDOUT.puts "precompiling assets ..."
10
+ end
11
+ end
@@ -11,6 +11,7 @@ list:
11
11
  - - config/environments/production.rb
12
12
  - - config/locales/**/*
13
13
  - - config/routes.rb
14
+ - - config/storage.yml
14
15
  - - app/**/*
15
16
  - - db/migrate/**/*
16
17
  - - public/javascripts/**/*
data/spec/config_spec.rb CHANGED
@@ -1,109 +1,114 @@
1
- require "yaml"
2
- require "fileutils"
3
- require "minitest/autorun"
1
+ require 'yaml'
2
+ require 'fileutils'
3
+ require 'minitest/autorun'
4
+ require 'minitest/focus'
4
5
  require "#{File.expand_path(File.dirname(__FILE__))}/../lib/traquitana.rb"
5
6
 
6
7
  describe Traquitana::Config do
7
- before do
8
- @config = Traquitana::Config.instance
9
- end
10
-
11
- describe "paths" do
12
- it "should have a filename getter method" do
13
- @config.must_respond_to(:filename)
14
- end
15
-
16
- it "should have a filename called traq.yml if file name is not set" do
17
- File.basename(@config.filename).must_equal("traq.yml")
18
- end
19
-
20
- it "should have a filename setter method" do
21
- @config.must_respond_to(:filename=)
22
- end
23
-
24
- it "should have a custom filename if filename is set" do
25
- old = @config.filename
26
- custom = "config/custom.yml"
27
- @config.filename = custom
28
- @config.filename.must_equal custom
29
- @config.filename = old
30
- end
31
-
32
- it "should have a default file method" do
33
- @config.must_respond_to(:default)
34
- end
35
-
36
- it "should have a valid directory" do
37
- @config.directory.wont_be_nil
38
- (@config.directory.size > 0).must_equal true
39
- end
40
- end
41
-
42
- describe "configs" do
43
- it "should respond to configuration dynamic methods" do
44
- @config.banana.must_equal ""
45
- end
46
-
47
- it "should respond with the correct value" do
48
- @config.load
49
- @config.user.must_equal "taq"
50
- end
51
-
52
- it "should have basic information on the default file" do
53
- contents = YAML.load(File.read(@config.default))
54
- contents["directory"].wont_be_nil
55
- contents["server"].wont_be_nil
56
- contents["list"].wont_be_nil
57
- contents["host"].wont_be_nil
58
- end
59
- end
60
-
61
- describe "setup" do
62
- it "should have a method named setup" do
63
- @config.must_respond_to(:setup)
64
- end
65
-
66
- it "should do nothing if the configuration file exists" do
67
- @config.setup.must_equal false
68
- end
69
-
70
- it "should write the configuration file if it doesn't exists" do
71
- contents = File.read(@config.filename)
72
- File.unlink(@config.filename)
73
-
74
- assert !File.exists?(@config.filename)
75
- @config.setup.must_equal true
76
- assert File.exists?(@config.filename)
77
-
78
- File.open(@config.filename,"w") {|file| file << contents}
8
+ before do
9
+ @config = Traquitana::Config.instance
10
+ end
11
+
12
+ describe 'paths' do
13
+ it 'should have a filename getter method' do
14
+ expect(@config).must_respond_to :filename
15
+ end
16
+
17
+ it 'should have a filename called traq.yml if file name is not set' do
18
+ expect(File.basename(@config.filename)).must_equal('traq.yml')
19
+ end
20
+
21
+ it 'should have a filename setter method' do
22
+ expect(@config).must_respond_to :filename=
23
+ end
24
+
25
+ it 'should have a custom filename if filename is set' do
26
+ old = @config.filename
27
+ custom = 'config/custom.yml'
28
+
29
+ @config.filename = custom
30
+ expect(@config.filename).must_equal custom
31
+ @config.filename = old
32
+ end
33
+
34
+ it 'should have a default file method' do
35
+ expect(@config).must_respond_to :default
36
+ end
37
+
38
+ it 'should have a valid directory' do
39
+ expect(@config.directory).wont_be_nil
40
+ expect(@config.directory.size > 0).must_equal true
41
+ end
42
+ end
43
+
44
+ describe 'configs' do
45
+ it 'should respond to configuration dynamic methods' do
46
+ expect(@config.banana).must_equal ''
47
+ end
48
+
49
+ it 'should respond with the correct value' do
50
+ @config.load
51
+ expect(@config.user).must_equal 'taq'
52
+ end
53
+
54
+ it 'should have basic information on the default file' do
55
+ contents = YAML.load(File.read(@config.default))
56
+ expect(contents['directory']).wont_be_nil
57
+ expect(contents['server']).wont_be_nil
58
+ expect(contents['list']).wont_be_nil
59
+ expect(contents['host']).wont_be_nil
60
+ end
61
+ end
62
+
63
+ describe 'setup' do
64
+ it 'should have a method named setup' do
65
+ expect(@config).must_respond_to :setup
66
+ end
67
+
68
+ it 'should do nothing if the configuration file exists' do
69
+ expect(@config.setup).must_equal false
70
+ end
71
+
72
+ it 'should write the configuration file if it doesnt exists' do
73
+ contents = File.read(@config.filename)
74
+ File.unlink(@config.filename)
75
+
76
+ expect(File.exists?(@config.filename)).must_equal false
77
+ expect(@config.setup).must_equal true
78
+ expect(File.exists?(@config.filename)).must_equal true
79
+
80
+ File.open(@config.filename, 'w') do |file|
81
+ file << contents
79
82
  end
80
- end
81
-
82
- describe "targets" do
83
- it "should have a target readable attribute" do
84
- @config.must_respond_to :target
83
+ end
84
+ end
85
+
86
+ describe 'targets' do
87
+ it 'should have a target readable attribute' do
88
+ expect(@config).must_respond_to :target
89
+ end
90
+
91
+ it 'should have a target writable attribute' do
92
+ expect(@config).must_respond_to :target=
93
+ end
94
+
95
+ it 'should load custom target config' do
96
+ begin
97
+ @config.filename = 'config/custom.yml'
98
+ @config.target = 'custom'
99
+ @config.load
100
+ expect(@config.directory).must_equal '/tmp/traq_test_custom'
101
+ ensure
102
+ reset_config
85
103
  end
104
+ end
105
+ end
86
106
 
87
- it "should have a target writable attribute" do
88
- @config.must_respond_to :target=
89
- end
107
+ private
90
108
 
91
- it "should load custom target config" do
92
- begin
93
- @config.filename = "config/custom.yml"
94
- @config.target = "custom"
95
- @config.load
96
- @config.directory.must_equal "/tmp/traq_test_custom"
97
- ensure
98
- reset_config
99
- end
100
- end
101
- end
102
-
103
- private
104
- def reset_config
105
- @config.filename = "config/traq.yml"
106
- @config.target = nil
107
- @config.load
108
- end
109
+ def reset_config
110
+ @config.filename = 'config/traq.yml'
111
+ @config.target = nil
112
+ @config.load
113
+ end
109
114
  end