contracto 0.0.9 → 0.0.10
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.
- checksums.yaml +8 -8
- data/lib/contracto.rb +1 -0
- data/lib/contracto/errors.rb +5 -0
- data/lib/contracto/installer.rb +34 -7
- data/lib/contracto/runner.rb +10 -6
- data/lib/contracto/runner/base.rb +24 -0
- data/lib/contracto/runner/local.rb +5 -0
- data/lib/contracto/runner/remote.rb +29 -0
- data/lib/contracto/server/ruby/contract.cdc.rb +2 -2
- data/lib/contracto/server/ruby/server.rb +2 -2
- data/lib/contracto/version.rb +1 -1
- metadata +5 -2
- data/lib/contracto/installer/local.rb +0 -38
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MjhlNmFiMGM1YWEyYmYwMTc3MjIzMGFlYTRhMTZjODFmZTQ2NTc4NA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
M2E3ODcwNmNmYjI1NDFlYWRhZDI5NjYzNzJmMTc1YzBkYTlkOGNlNg==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MDIzMzhkMTFlODI3ZDUyMzdkMzMyMmViOTVmZTMyMzEwYWRkNGZiY2IxYmZm
|
10
|
+
NzNjODk5YjA2MTQyNzIwZDI3YzgwMzRhZDJiZWNhMTFhYTc2Nzg4NDk2NTJi
|
11
|
+
MDU4NTMzYmExMjJjOGY2NTZmZGFmMmEwYjU2YjJjYzI1NzVjZGM=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZjE5NDBjNmNhMWU5NmU3NTIwYzQxZWMyYjYxYjhkYTVmYjE3NzMzZDc3NWQw
|
14
|
+
MmIzYTE3MDZkMzkyYWYxOTZjYmYxOWYzNzNhZDg1YmRlODlhM2U3ODljOTkz
|
15
|
+
Y2IzMTQyYmM4NDI2OGIzOGYxYzA3YWI5YjVjNDFjMDBlOGUzNDg=
|
data/lib/contracto.rb
CHANGED
@@ -8,6 +8,7 @@ module Contracto
|
|
8
8
|
CONTRACT_FILENAME = 'contract.cdc.rb'
|
9
9
|
CONTRACT_PID_FILEPATH = "#{CONTRACTO_DIR}/server.pid"
|
10
10
|
|
11
|
+
require_relative 'contracto/errors'
|
11
12
|
require_relative 'contracto/installer'
|
12
13
|
require_relative 'contracto/runner'
|
13
14
|
require_relative 'contracto/terminator'
|
data/lib/contracto/installer.rb
CHANGED
@@ -1,13 +1,40 @@
|
|
1
|
-
|
2
|
-
require_relative 'installer/local'
|
1
|
+
require 'fileutils'
|
3
2
|
|
3
|
+
class Contracto::Installer
|
4
4
|
def initialize(args)
|
5
|
-
if args.empty?
|
6
|
-
@strategy = Contracto::Installer::Local.new
|
7
|
-
end
|
8
5
|
end
|
9
6
|
|
10
7
|
def execute
|
11
|
-
|
8
|
+
remove_old_dir
|
9
|
+
cp_server_files
|
10
|
+
create_contract unless contract_already_exists?
|
11
|
+
puts 'contracto initialized'
|
12
|
+
puts "start writing contracts in #{Contracto::CONTRACT_FILENAME}"
|
13
|
+
rescue
|
14
|
+
revert
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def remove_old_dir
|
20
|
+
FileUtils.rm_rf Contracto::CONTRACTO_DIR
|
21
|
+
end
|
22
|
+
|
23
|
+
def cp_server_files
|
24
|
+
FileUtils.cp_r Contracto::RUBY_SERVER_DIR, Contracto::CONTRACTO_TMP_DIR
|
25
|
+
FileUtils.mv Contracto::CONTRACTO_TMP_DIR, Contracto::CONTRACTO_DIR
|
26
|
+
end
|
27
|
+
|
28
|
+
def create_contract
|
29
|
+
FileUtils.mv "#{Contracto::CONTRACTO_DIR}/#{Contracto::CONTRACT_FILENAME}", FileUtils.pwd
|
30
|
+
puts "created: #{installer.CONTRACT_FILENAME}"
|
31
|
+
end
|
32
|
+
|
33
|
+
def contract_already_exists?
|
34
|
+
File.exist? Contracto::CONTRACT_FILENAME
|
35
|
+
end
|
36
|
+
|
37
|
+
def revert
|
38
|
+
# TODO: implement
|
12
39
|
end
|
13
|
-
end
|
40
|
+
end
|
data/lib/contracto/runner.rb
CHANGED
@@ -1,13 +1,17 @@
|
|
1
1
|
class Contracto::Runner
|
2
|
-
|
2
|
+
require_relative 'runner/base'
|
3
|
+
require_relative 'runner/remote'
|
4
|
+
require_relative 'runner/local'
|
3
5
|
|
4
6
|
def initialize(args)
|
7
|
+
if args.first
|
8
|
+
@strategy = Contracto::Runner::Remote.new(args)
|
9
|
+
else
|
10
|
+
@strategy = Contracto::Runner::Local.new(args)
|
11
|
+
end
|
5
12
|
end
|
6
13
|
|
7
14
|
def execute
|
8
|
-
|
9
|
-
# TODO: loop below should terminate after n tries
|
10
|
-
system "while ! echo exit | nc localhost #{PORT} > /dev/null && echo \"Waiting for server...\"; do sleep 1; done"
|
11
|
-
system "curl 0.0.0.0:#{PORT}"
|
15
|
+
@strategy.execute
|
12
16
|
end
|
13
|
-
end
|
17
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
class Contracto::Runner::Base
|
2
|
+
PORT = 54321
|
3
|
+
|
4
|
+
def initialize(args)
|
5
|
+
@args = args
|
6
|
+
end
|
7
|
+
|
8
|
+
def execute
|
9
|
+
raise NotImplementedError
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def start_server
|
15
|
+
system "rackup #{Contracto::CONTRACTO_DIR}/config.ru -p #{PORT} -D -P #{Contracto::CONTRACT_PID_FILEPATH}"
|
16
|
+
# TODO: loop below should terminate after n tries
|
17
|
+
system "while ! echo exit | nc localhost #{PORT} > /dev/null && echo \"waiting for contracto server...\"; do sleep 1; done"
|
18
|
+
system "curl 0.0.0.0:#{PORT}"
|
19
|
+
end
|
20
|
+
|
21
|
+
def server_repo_url
|
22
|
+
@args.first
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
class Contracto::Runner::Remote < Contracto::Runner::Base
|
2
|
+
require 'fileutils'
|
3
|
+
|
4
|
+
def execute
|
5
|
+
puts 'downloading contract...'
|
6
|
+
clone_repo || raise(Contracto::CouldNotDownloadContractError.new(server_repo_url))
|
7
|
+
mv_repo_files_to_current_dir
|
8
|
+
remove_old_repo_dir
|
9
|
+
start_server
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def clone_repo
|
15
|
+
system "git clone -q --depth 1 --single-branch --branch master #{server_repo_url} #{tmp_dir}"
|
16
|
+
end
|
17
|
+
|
18
|
+
def mv_repo_files_to_current_dir
|
19
|
+
system "mv #{tmp_dir}/* #{tmp_dir}/.[^.]* . 2> /dev/null" # Could not use FileUtils for some reason
|
20
|
+
end
|
21
|
+
|
22
|
+
def remove_old_repo_dir
|
23
|
+
FileUtils.rm_rf tmp_dir
|
24
|
+
end
|
25
|
+
|
26
|
+
def tmp_dir
|
27
|
+
Contracto::CONTRACTO_TMP_DIR
|
28
|
+
end
|
29
|
+
end
|
data/lib/contracto/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: contracto
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kacper Walanus
|
@@ -69,9 +69,12 @@ files:
|
|
69
69
|
- contracto.gemspec
|
70
70
|
- lib/contracto.rb
|
71
71
|
- lib/contracto/command.rb
|
72
|
+
- lib/contracto/errors.rb
|
72
73
|
- lib/contracto/installer.rb
|
73
|
-
- lib/contracto/installer/local.rb
|
74
74
|
- lib/contracto/runner.rb
|
75
|
+
- lib/contracto/runner/base.rb
|
76
|
+
- lib/contracto/runner/local.rb
|
77
|
+
- lib/contracto/runner/remote.rb
|
75
78
|
- lib/contracto/server/ruby/config.ru
|
76
79
|
- lib/contracto/server/ruby/contract.cdc.rb
|
77
80
|
- lib/contracto/server/ruby/server.rb
|
@@ -1,38 +0,0 @@
|
|
1
|
-
require 'fileutils'
|
2
|
-
|
3
|
-
class Contracto::Installer::Local
|
4
|
-
|
5
|
-
def execute
|
6
|
-
remove_old_dir
|
7
|
-
cp_server_files
|
8
|
-
create_contract unless contract_already_exists?
|
9
|
-
puts 'contracto initialized'
|
10
|
-
puts "start writing contracts in #{Contracto::CONTRACT_FILENAME}"
|
11
|
-
rescue
|
12
|
-
revert
|
13
|
-
end
|
14
|
-
|
15
|
-
private
|
16
|
-
|
17
|
-
def remove_old_dir
|
18
|
-
FileUtils.rm_rf Contracto::CONTRACTO_DIR
|
19
|
-
end
|
20
|
-
|
21
|
-
def cp_server_files
|
22
|
-
FileUtils.cp_r Contracto::RUBY_SERVER_DIR, Contracto::CONTRACTO_TMP_DIR
|
23
|
-
FileUtils.mv Contracto::CONTRACTO_TMP_DIR, Contracto::CONTRACTO_DIR
|
24
|
-
end
|
25
|
-
|
26
|
-
def create_contract
|
27
|
-
FileUtils.mv "#{Contracto::CONTRACTO_DIR}/#{Contracto::CONTRACT_FILENAME}", FileUtils.pwd
|
28
|
-
puts "created: #{installer.CONTRACT_FILENAME}"
|
29
|
-
end
|
30
|
-
|
31
|
-
def contract_already_exists?
|
32
|
-
File.exist? Contracto::CONTRACT_FILENAME
|
33
|
-
end
|
34
|
-
|
35
|
-
def revert
|
36
|
-
# TODO: implement
|
37
|
-
end
|
38
|
-
end
|