contracto 0.1.0 → 0.2.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6005fbde75b11e623c24520cb900b7b67d8c4d22
4
- data.tar.gz: c6361eb19b087c19362defca14119539279254fe
3
+ metadata.gz: 58f8e5bbd43d3c7f0cc80462dd1c199a6c734b57
4
+ data.tar.gz: 2d9e6e2a914a81128f0e6aea61cf1dec04451328
5
5
  SHA512:
6
- metadata.gz: f8c4f59416fd12ca16374540b24107850b0fa0ffb6f3d78112bc989bc67ecb19ac96b3b392f0b11d6f645c7f6b724d750ede6a36ceef6efde69dcd7f156c62f9
7
- data.tar.gz: e38db2813dec339fea3215547651fd5e958d7b713e7ad9f1d1e2ad27d7a2e822212741d43f587721d0fcfac01bb4c2f944f2dfcda002aaaea5633207af12f51e
6
+ metadata.gz: 3d31d65158ca0e151e0e30eaa207cff7a87ef4595030770aad0e55f8f4ebc83ef4a48a286c0105ff21401a6c5460125682c3fc48b447042ef5513378551bb6c6
7
+ data.tar.gz: 0890abb491534d3f6e3c14329f2061fccf06f88a85b7d294714570f72bf0f54e4da5ec5bed6de2d435e4274047d566f390efc6d13fb5b1fc206dab30d3f356e8
data/contracto.gemspec CHANGED
@@ -22,6 +22,7 @@ Gem::Specification.new do |spec|
22
22
 
23
23
  spec.add_runtime_dependency 'sinatra', '~> 1.4'
24
24
 
25
+ spec.add_development_dependency 'rspec', '~> 3.2'
25
26
  spec.add_development_dependency 'bundler', '~> 1.7'
26
27
  spec.add_development_dependency 'rake', '~> 10.0'
27
28
  end
data/lib/contracto.rb CHANGED
@@ -1,15 +1,11 @@
1
1
  require_relative 'contracto/version' # TODO: replace all #require with #require_relative
2
2
 
3
3
  module Contracto
4
- GEM_DIR = Gem::Specification.find_by_name('contracto').gem_dir
5
- CONTRACTO_DIR = 'contracto'
6
- CONTRACTO_TMP_DIR = '.tmp.contracto'
7
- RUBY_SERVER_DIR = "#{GEM_DIR}/lib/contracto/server/ruby"
8
- CONTRACT_FILENAME = 'contract.cdc.rb'
9
- CONTRACT_PID_FILEPATH = "#{CONTRACTO_DIR}/server.pid"
10
-
11
4
  require_relative 'contracto/errors'
12
- require_relative 'contracto/installer'
13
- require_relative 'contracto/runner'
14
- require_relative 'contracto/terminator'
5
+ require_relative 'contracto/constants'
6
+ require_relative 'contracto/config'
7
+ require_relative 'contracto/contract'
8
+ require_relative 'contracto/parser'
9
+ require_relative 'contracto/system_action_chain'
10
+ require_relative 'contracto/command'
15
11
  end
@@ -1,14 +1,17 @@
1
1
  class Contracto::Command
2
+ require_relative 'command/init'
3
+ require_relative 'command/start'
4
+ require_relative 'command/stop'
2
5
  class << self
3
6
 
4
7
  def run(command, args)
5
8
  case command
6
9
  when 'init'
7
- Contracto::Installer.new(args).execute
10
+ Contracto::Command::Init.new(args).execute
8
11
  when 'start'
9
- Contracto::Runner.new(args).execute
12
+ Contracto::Command::Start.new(args).execute
10
13
  when 'stop'
11
- Contracto::Terminator.new(args).execute
14
+ Contracto::Command::Stop.new(args).execute
12
15
  end
13
16
  end
14
17
  end
@@ -0,0 +1,24 @@
1
+ class Contracto::Command::Init
2
+ def initialize(args)
3
+ end
4
+
5
+ def execute
6
+ initialized = Contracto::SystemActionChain.new(*actions).execute
7
+
8
+ if initialized
9
+ puts 'contract initialized, enter \'contracto start\' to start server'
10
+ else
11
+ puts 'initializing contract failed'
12
+ end
13
+ end
14
+
15
+ private
16
+
17
+ def actions
18
+ [
19
+ :remove_contracto_dir,
20
+ :copy_server_files,
21
+ :create_sample_contract
22
+ ]
23
+ end
24
+ end
@@ -0,0 +1,16 @@
1
+ class Contracto::Command::Start
2
+ require_relative 'start/remote'
3
+ require_relative 'start/local'
4
+
5
+ def initialize(args)
6
+ if args.first
7
+ @strategy = Contracto::Command::Start::Remote.new(args.first)
8
+ else
9
+ @strategy = Contracto::Command::Start::Local.new
10
+ end
11
+ end
12
+
13
+ def execute
14
+ @strategy.execute
15
+ end
16
+ end
@@ -0,0 +1,11 @@
1
+ class Contracto::Command::Start::Local
2
+ def execute
3
+ Contracto::SystemActionChain.new(*actions).execute
4
+ end
5
+
6
+ private
7
+
8
+ def actions
9
+ [:start_server]
10
+ end
11
+ end
@@ -0,0 +1,22 @@
1
+ class Contracto::Command::Start::Remote
2
+ def initialize(repo_url)
3
+ Contracto::Config.repo_url = repo_url
4
+ end
5
+
6
+ def execute
7
+ puts "downloading contract from #{Contracto::Config.repo_url}"
8
+ Contracto::SystemActionChain.new(*actions).execute
9
+ end
10
+
11
+ private
12
+
13
+ def actions
14
+ [
15
+ :clone_repo_to_tmp_contracto_dir,
16
+ :move_repo_files_to_root_dir,
17
+ :remove_tmp_contracto_dir,
18
+ :copy_server_files,
19
+ :start_server
20
+ ]
21
+ end
22
+ end
@@ -0,0 +1,14 @@
1
+ class Contracto::Command::Stop
2
+ def initialize(args)
3
+ end
4
+
5
+ def execute
6
+ Contracto::SystemActionChain.new(*actions).execute
7
+ end
8
+
9
+ private
10
+
11
+ def actions
12
+ [:stop_server]
13
+ end
14
+ end
@@ -0,0 +1,11 @@
1
+ class Contracto::Config
2
+ class << self
3
+ def repo_url=(repo_url)
4
+ @repo_url = repo_url
5
+ end
6
+
7
+ def repo_url
8
+ @repo_url
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,37 @@
1
+ module Contracto::Constants
2
+ GEM_DIR = Gem::Specification.find_by_name('contracto').gem_dir
3
+ CONTRACTO_DIR = '.contracto'
4
+ CONTRACTO_TMP_DIR = '.tmp.contracto'
5
+ RUBY_SERVER_DIR = "#{GEM_DIR}/lib/contracto/server/ruby"
6
+ CONTRACT_FILENAME = 'contract.con.json'
7
+ CONTRACT_PID_FILEPATH = "#{CONTRACTO_DIR}/server.pid"
8
+ PORT = 54321
9
+
10
+ def gem_dir
11
+ GEM_DIR
12
+ end
13
+
14
+ def contracto_dir
15
+ CONTRACTO_DIR
16
+ end
17
+
18
+ def contracto_tmp_dir
19
+ CONTRACTO_TMP_DIR
20
+ end
21
+
22
+ def ruby_server_dir
23
+ RUBY_SERVER_DIR
24
+ end
25
+
26
+ def contract_filename
27
+ CONTRACT_FILENAME
28
+ end
29
+
30
+ def contract_pid_filepath
31
+ CONTRACT_PID_FILEPATH
32
+ end
33
+
34
+ def port
35
+ PORT
36
+ end
37
+ end
@@ -0,0 +1,32 @@
1
+ class Contracto::Contract
2
+ def initialize(hash)
3
+ @hash = hash
4
+ @request = Contracto::Contract::Request.new(@hash.fetch('request'))
5
+ end
6
+
7
+ def http_method
8
+ @request.http_method
9
+ end
10
+
11
+ def url_pattern
12
+ @request.url_pattern
13
+ end
14
+
15
+ def response_body(params)
16
+ params.to_s
17
+ end
18
+
19
+ class Contracto::Contract::Request
20
+ def initialize(hash)
21
+ @hash = hash
22
+ end
23
+
24
+ def http_method
25
+ @hash.fetch('http_method')
26
+ end
27
+
28
+ def url_pattern
29
+ @hash.fetch('path')
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,15 @@
1
+ require 'json'
2
+
3
+ class Contracto::Parser
4
+ def initialize(strings_with_json)
5
+ @json_collection = strings_with_json.map { |string| JSON.parse(string) }
6
+ end
7
+
8
+ def contracts
9
+ @json_collection.map do |json|
10
+ Array(json).map do |json|
11
+ Contracto::Contract.new(json)
12
+ end
13
+ end.flatten
14
+ end
15
+ end
@@ -0,0 +1,46 @@
1
+ [
2
+ {
3
+ "request": {
4
+ "http_method": "get",
5
+ "path": "/users"
6
+ },
7
+ "examples": [
8
+ {
9
+ "request": {
10
+ "headers": {
11
+ "Content-Type": "application/json"
12
+ },
13
+ "body": {
14
+ "firstName": "Max",
15
+ "lastName": "Lincoln"
16
+ }
17
+ },
18
+ "response": {
19
+ "body": {}
20
+ }
21
+ }
22
+ ]
23
+ },
24
+ {
25
+ "request": {
26
+ "http_method": "get",
27
+ "path": "/users/:id"
28
+ },
29
+ "examples": [
30
+ {
31
+ "request": {
32
+ "headers": {
33
+ "Content-Type": "application/json"
34
+ },
35
+ "body": {
36
+ "firstName": "Max",
37
+ "lastName": "Lincoln"
38
+ }
39
+ },
40
+ "response": {
41
+ "body": {}
42
+ }
43
+ }
44
+ ]
45
+ }
46
+ ]
@@ -1,8 +1,17 @@
1
1
  require 'sinatra'
2
+ require 'contracto'
2
3
 
3
4
  get '/contracto' do
4
5
  "*** Contracto server is working! [#{Gem::Specification.find_by_name('contracto').version}] ***"
5
6
  end
6
7
 
7
- require './contract.cdc.rb'
8
+ json_string = File.read Contracto::Constants::CONTRACT_FILENAME
9
+ json_strings = [json_string]
10
+
11
+ Contracto::Parser.new(json_strings).contracts.each do |contract|
12
+ send(contract.http_method, contract.url_pattern) do
13
+ contract.response_body(params)
14
+ end
15
+ end
16
+
8
17
 
@@ -0,0 +1,125 @@
1
+ class Contracto::SystemAction
2
+ class << self
3
+ include Contracto::Constants
4
+
5
+ def remove_contracto_dir
6
+ FileUtils.rm_rf contracto_dir
7
+ end
8
+
9
+ def remove_tmp_contracto_dir
10
+ FileUtils.rm_rf contracto_tmp_dir
11
+ end
12
+
13
+ def copy_server_files
14
+ FileUtils.cp_r ruby_server_dir, contracto_tmp_dir
15
+ FileUtils.mv contracto_tmp_dir, contracto_dir
16
+ end
17
+
18
+ def revert_copy_server_files
19
+ remove_contracto_dir
20
+ remove_tmp_contracto_dir
21
+ end
22
+
23
+ def create_sample_contract
24
+ if contract_already_exists?
25
+ puts 'contract already exists, creating sample contract skipped'
26
+ remove_sample_contract
27
+ else
28
+ FileUtils.mv sample_contract_path, FileUtils.pwd
29
+ puts "created: #{contract_filename}"
30
+ end
31
+ end
32
+
33
+ def start_server
34
+ raise Contracto::ServerAlreadyRunningError if server_already_running?
35
+
36
+ system "rackup #{contracto_dir}/config.ru -p #{port} -D -P #{contract_pid_filepath}"
37
+ # TODO: loop below should terminate after n tries
38
+ system "while ! echo exit | nc localhost #{port} > /dev/null && echo \"waiting for contracto server...\"; do sleep 1; done"
39
+ test_request
40
+ end
41
+
42
+ def stop_server
43
+ puts 'killing server...'
44
+ Process.kill(15, File.read(contract_pid_filepath).to_i)
45
+ puts '...server killed'
46
+ rescue Errno::ENOENT
47
+ puts 'could not kill server (pidfile not found)'
48
+ end
49
+
50
+ def revert_start_server
51
+ stop_server
52
+ rescue StandardError
53
+ end
54
+
55
+ def clone_repo_to_tmp_contracto_dir
56
+ success = system "git clone -q --depth 1 --single-branch --branch master #{Contracto::Config.repo_url} #{contracto_tmp_dir}"
57
+ raise(Contracto::CouldNotDownloadContractError.new(Contracto::Config.repo_url)) unless success
58
+ end
59
+
60
+ def revert_clone_repo_to_tmp_contracto_dir
61
+ remove_tmp_contracto_dir
62
+ end
63
+
64
+ def move_repo_files_to_root_dir
65
+ system "mv #{contracto_tmp_dir}/* #{contracto_tmp_dir}/.[^.]* . 2> /dev/null" # Could not use FileUtils for some reason
66
+ end
67
+
68
+ private
69
+
70
+ def contract_already_exists?
71
+ File.exist?(contract_filename)
72
+ end
73
+
74
+ def remove_sample_contract
75
+ FileUtils.rm sample_contract_path
76
+ end
77
+
78
+ def sample_contract_path
79
+ "#{contracto_dir}/#{contract_filename}"
80
+ end
81
+
82
+ def server_already_running?
83
+ test_request(silent: true)
84
+ end
85
+
86
+ def test_request(options = {})
87
+ args = ''
88
+ args << '-s -o /dev/null' if options[:silent]
89
+ system "curl #{args} 0.0.0.0:#{port}/contracto"
90
+ end
91
+ end
92
+ end
93
+
94
+ class Contracto::SystemActionChain
95
+ def initialize(*actions)
96
+ @actions = actions
97
+ @finished_actions = []
98
+ end
99
+
100
+ def execute
101
+ perform_actions and true
102
+ rescue StandardError => e
103
+ revert_actions and false
104
+ raise e
105
+ end
106
+
107
+ private
108
+
109
+ def perform_actions
110
+ @actions.each do |action|
111
+ @finished_actions << action
112
+ Contracto::SystemAction.send(action)
113
+ end
114
+ end
115
+
116
+ def revert_actions
117
+ @finished_actions.reverse.each do |action|
118
+ revert_method_name = "revert_#{action}"
119
+ if Contracto::SystemAction.respond_to? revert_method_name
120
+ Contracto::SystemAction.send revert_method_name
121
+ end
122
+ end
123
+ rescue StandardError
124
+ end
125
+ end
@@ -0,0 +1,34 @@
1
+ class Contracto::SystemActionChain
2
+ require_relative 'system_action'
3
+
4
+ def initialize(*actions)
5
+ @actions = actions
6
+ @finished_actions = []
7
+ end
8
+
9
+ def execute
10
+ perform_actions and true
11
+ rescue StandardError => e
12
+ revert_actions and false
13
+ raise e
14
+ end
15
+
16
+ private
17
+
18
+ def perform_actions
19
+ @actions.each do |action|
20
+ @finished_actions << action
21
+ Contracto::SystemAction.send(action)
22
+ end
23
+ end
24
+
25
+ def revert_actions
26
+ @finished_actions.reverse.each do |action|
27
+ revert_method_name = "revert_#{action}"
28
+ if Contracto::SystemAction.respond_to? revert_method_name
29
+ Contracto::SystemAction.send revert_method_name
30
+ end
31
+ end
32
+ rescue StandardError
33
+ end
34
+ end
@@ -1,3 +1,3 @@
1
1
  module Contracto
2
- VERSION = '0.1.0'
2
+ VERSION = '0.2.0'
3
3
  end
@@ -5,3 +5,4 @@ cd tmp
5
5
  contracto start https://github.com/kv109/cdc-sample-contract.git
6
6
  contracto stop
7
7
  cd ..
8
+ rm -rf tmp
@@ -6,3 +6,4 @@ contracto init
6
6
  contracto start
7
7
  contracto stop
8
8
  cd ..
9
+ rm -rf tmp
@@ -0,0 +1,52 @@
1
+ require_relative '../lib/contracto'
2
+
3
+ STRINGS_WITH_JSON = []
4
+ STRINGS_WITH_JSON << <<JSON
5
+ {
6
+ "request": {
7
+ "http_method": "get",
8
+ "path": "/api/users"
9
+ },
10
+ "examples": [
11
+ {
12
+ "request": {
13
+ "headers": {
14
+ "Content-Type": "application/json"
15
+ },
16
+ "body": {
17
+ "firstName": "Max",
18
+ "lastName": "Lincoln"
19
+ }
20
+ },
21
+ "response": {
22
+ "body": { }
23
+ }
24
+ }
25
+ ]
26
+ }
27
+ JSON
28
+
29
+ STRINGS_WITH_JSON << <<JSON
30
+ {
31
+ "request": {
32
+ "http_method": "get",
33
+ "path": "/api/users/:id"
34
+ },
35
+ "examples": [
36
+ {
37
+ "request": {
38
+ "headers": {
39
+ "Content-Type": "application/json"
40
+ },
41
+ "body": {
42
+ "firstName": "Max",
43
+ "lastName": "Lincoln"
44
+ }
45
+ },
46
+ "response": {
47
+ "body": { }
48
+ }
49
+ }
50
+ ]
51
+ }
52
+ JSON
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Contracto::Parser do
4
+ context '#contracts' do
5
+ subject { described_class.new(STRINGS_WITH_JSON).contracts }
6
+
7
+ it do
8
+ expect(subject).to be_a Array
9
+ expect(subject.first).to be_a Contracto::Contract
10
+ end
11
+ end
12
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: contracto
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kacper Walanus
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-15 00:00:00.000000000 Z
11
+ date: 2015-03-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sinatra
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.4'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.2'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.2'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: bundler
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -69,19 +83,26 @@ files:
69
83
  - contracto.gemspec
70
84
  - lib/contracto.rb
71
85
  - lib/contracto/command.rb
86
+ - lib/contracto/command/init.rb
87
+ - lib/contracto/command/start.rb
88
+ - lib/contracto/command/start/local.rb
89
+ - lib/contracto/command/start/remote.rb
90
+ - lib/contracto/command/stop.rb
91
+ - lib/contracto/config.rb
92
+ - lib/contracto/constants.rb
93
+ - lib/contracto/contract.rb
72
94
  - lib/contracto/errors.rb
73
- - lib/contracto/installer.rb
74
- - lib/contracto/runner.rb
75
- - lib/contracto/runner/base.rb
76
- - lib/contracto/runner/local.rb
77
- - lib/contracto/runner/remote.rb
95
+ - lib/contracto/parser.rb
78
96
  - lib/contracto/server/ruby/config.ru
79
- - lib/contracto/server/ruby/contract.cdc.rb
97
+ - lib/contracto/server/ruby/contract.con.json
80
98
  - lib/contracto/server/ruby/server.rb
81
- - lib/contracto/terminator.rb
99
+ - lib/contracto/system_action.rb
100
+ - lib/contracto/system_action_chain.rb
82
101
  - lib/contracto/version.rb
83
102
  - script/start_from_remote.sh
84
103
  - script/start_locally.sh
104
+ - spec/spec_helper.rb
105
+ - spec/unit/parser_spec.rb
85
106
  homepage: ''
86
107
  licenses:
87
108
  - MIT
@@ -106,4 +127,6 @@ rubygems_version: 2.4.6
106
127
  signing_key:
107
128
  specification_version: 4
108
129
  summary: XXX
109
- test_files: []
130
+ test_files:
131
+ - spec/spec_helper.rb
132
+ - spec/unit/parser_spec.rb
@@ -1,52 +0,0 @@
1
- require 'fileutils'
2
-
3
- class Contracto::Installer
4
- def initialize(args)
5
- end
6
-
7
- def execute
8
- remove_old_dir
9
- cp_server_files
10
- if contract_already_exists?
11
- remove_sample_contract_file
12
- else
13
- create_contract
14
- end
15
- puts 'contracto initialized'
16
- puts "start writing contracts in #{Contracto::CONTRACT_FILENAME}"
17
- rescue
18
- revert
19
- end
20
-
21
- private
22
-
23
- def remove_old_dir
24
- FileUtils.rm_rf Contracto::CONTRACTO_DIR
25
- end
26
-
27
- def cp_server_files
28
- FileUtils.cp_r Contracto::RUBY_SERVER_DIR, Contracto::CONTRACTO_TMP_DIR
29
- FileUtils.mv Contracto::CONTRACTO_TMP_DIR, Contracto::CONTRACTO_DIR
30
- end
31
-
32
- def create_contract
33
- FileUtils.mv sample_contract_path, FileUtils.pwd
34
- puts "created: #{installer.CONTRACT_FILENAME}"
35
- end
36
-
37
- def contract_already_exists?
38
- File.exist? Contracto::CONTRACT_FILENAME
39
- end
40
-
41
- def remove_sample_contract_file
42
- FileUtils.rm sample_contract_path
43
- end
44
-
45
- def sample_contract_path
46
- "#{Contracto::CONTRACTO_DIR}/#{Contracto::CONTRACT_FILENAME}"
47
- end
48
-
49
- def revert
50
- # TODO: implement
51
- end
52
- end
@@ -1,17 +0,0 @@
1
- class Contracto::Runner
2
- require_relative 'runner/base'
3
- require_relative 'runner/remote'
4
- require_relative 'runner/local'
5
-
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
12
- end
13
-
14
- def execute
15
- @strategy.execute
16
- end
17
- end
@@ -1,36 +0,0 @@
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
- raise Contracto::ServerAlreadyRunningError if server_already_running?
16
-
17
- system "rackup #{Contracto::CONTRACTO_DIR}/config.ru -p #{PORT} -D -P #{Contracto::CONTRACT_PID_FILEPATH}"
18
- # TODO: loop below should terminate after n tries
19
- system "while ! echo exit | nc localhost #{PORT} > /dev/null && echo \"waiting for contracto server...\"; do sleep 1; done"
20
- test_request
21
- end
22
-
23
- def server_already_running?
24
- test_request(silent: true)
25
- end
26
-
27
- def test_request(options = {})
28
- args = ''
29
- args << '-s -o /dev/null' if options[:silent]
30
- system "curl #{args} 0.0.0.0:#{PORT}/contracto"
31
- end
32
-
33
- def server_repo_url
34
- @args.first
35
- end
36
- end
@@ -1,5 +0,0 @@
1
- class Contracto::Runner::Local < Contracto::Runner::Base
2
- def execute
3
- start_server
4
- end
5
- end
@@ -1,29 +0,0 @@
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
@@ -1,5 +0,0 @@
1
- # TODO: Should require all *.cdc.rb files
2
-
3
- get '/dummy' do
4
- 'You can start working on your contract'
5
- end
@@ -1,10 +0,0 @@
1
- class Contracto::Terminator
2
- def initialize(args)
3
- end
4
-
5
- def execute
6
- puts 'killing server...'
7
- Process.kill(15, File.read(Contracto::CONTRACT_PID_FILEPATH).to_i)
8
- puts 'server terminated'
9
- end
10
- end