contracto 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/contracto.gemspec +1 -0
- data/lib/contracto/config.rb +11 -4
- data/lib/contracto/constants.rb +16 -36
- data/lib/contracto/contract/response.rb +1 -1
- data/lib/contracto/server/ruby/server.rb +16 -12
- data/lib/contracto/system_action.rb +20 -6
- data/lib/contracto/version.rb +1 -1
- data/lib/contracto.rb +4 -0
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 878cd05857b9fea82b17d7a5954073fe913f0dc5
|
4
|
+
data.tar.gz: 9dff5a72b030781058855be8144a5ae4fde47f97
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d7a9e463e67cdc5e56c0e194f075bf0d685e3e29066d3faf5414c17ec15f97ac5da739611edaac3d09caed076428823019e4e00c7a360157a885b445a453286a
|
7
|
+
data.tar.gz: 33451ca2f440f3ef74e8c016e5ff3496f66a1212c1972d2811f978470e8beea887d9f20256bcf370069cb7541fe36fe37d255fcea129c96b9b61c7bd36e1c1d5
|
data/contracto.gemspec
CHANGED
@@ -21,6 +21,7 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.require_paths = ['lib']
|
22
22
|
|
23
23
|
spec.add_runtime_dependency 'sinatra', '~> 1.4'
|
24
|
+
spec.add_runtime_dependency 'daemons', '~> 1.2'
|
24
25
|
|
25
26
|
spec.add_development_dependency 'rspec', '~> 3.2'
|
26
27
|
spec.add_development_dependency 'bundler', '~> 1.7'
|
data/lib/contracto/config.rb
CHANGED
@@ -1,11 +1,18 @@
|
|
1
1
|
class Contracto::Config
|
2
|
+
extend Contracto::Constants
|
3
|
+
|
2
4
|
class << self
|
3
|
-
|
4
|
-
|
5
|
+
|
6
|
+
attr_accessor :repo_url
|
7
|
+
attr_accessor :root_dir
|
8
|
+
|
9
|
+
def configure
|
10
|
+
yield self if block_given?
|
5
11
|
end
|
6
12
|
|
7
|
-
def
|
8
|
-
@
|
13
|
+
def root_dir
|
14
|
+
@root_dir || default_root_dir
|
9
15
|
end
|
16
|
+
|
10
17
|
end
|
11
18
|
end
|
data/lib/contracto/constants.rb
CHANGED
@@ -2,48 +2,28 @@ module Contracto::Constants
|
|
2
2
|
require 'fileutils'
|
3
3
|
|
4
4
|
GEM_DIR = Gem::Specification.find_by_name('contracto').gem_dir
|
5
|
-
|
5
|
+
DEFAULT_ROOT_DIR = FileUtils.pwd
|
6
6
|
CONTRACTO_DIR = '.contracto'
|
7
7
|
CONTRACTO_TMP_DIR = '.tmp.contracto'
|
8
8
|
RUBY_SERVER_DIR = "#{GEM_DIR}/lib/contracto/server/ruby"
|
9
|
-
CONTRACT_FILENAME = 'contract.con.json'
|
9
|
+
CONTRACT_FILENAME = 'contract.con.json' # TODO: remove
|
10
10
|
SAMPLE_CONTRACT_DIR = "#{GEM_DIR}/spec/fixtures"
|
11
|
-
|
11
|
+
SERVER_PIDFILE_NAME = 'server'
|
12
12
|
PORT = 54321
|
13
13
|
|
14
|
-
|
15
|
-
|
14
|
+
%w(
|
15
|
+
gem_dir
|
16
|
+
default_root_dir
|
17
|
+
contracto_dir
|
18
|
+
contracto_tmp_dir
|
19
|
+
sample_contract_dir
|
20
|
+
contract_filename
|
21
|
+
server_pidfile_name
|
22
|
+
port
|
23
|
+
).each do |method_name|
|
24
|
+
define_method method_name do
|
25
|
+
Contracto::Constants.const_get method_name.upcase
|
26
|
+
end
|
16
27
|
end
|
17
28
|
|
18
|
-
def root_dir
|
19
|
-
ROOT_DIR
|
20
|
-
end
|
21
|
-
|
22
|
-
def contracto_dir
|
23
|
-
CONTRACTO_DIR
|
24
|
-
end
|
25
|
-
|
26
|
-
def contracto_tmp_dir
|
27
|
-
CONTRACTO_TMP_DIR
|
28
|
-
end
|
29
|
-
|
30
|
-
def ruby_server_dir
|
31
|
-
RUBY_SERVER_DIR
|
32
|
-
end
|
33
|
-
|
34
|
-
def sample_contract_dir
|
35
|
-
SAMPLE_CONTRACT_DIR
|
36
|
-
end
|
37
|
-
|
38
|
-
def contract_filename
|
39
|
-
CONTRACT_FILENAME
|
40
|
-
end
|
41
|
-
|
42
|
-
def contract_pid_filepath
|
43
|
-
CONTRACT_PID_FILEPATH
|
44
|
-
end
|
45
|
-
|
46
|
-
def port
|
47
|
-
PORT
|
48
|
-
end
|
49
29
|
end
|
@@ -1,18 +1,22 @@
|
|
1
|
-
require 'sinatra'
|
2
|
-
require 'contracto'
|
1
|
+
require 'sinatra/base'
|
3
2
|
|
4
|
-
|
5
|
-
"*** Contracto server is working! [#{Gem::Specification.find_by_name('contracto').version}] ***"
|
6
|
-
end
|
3
|
+
class Contracto::Server < Sinatra::Base
|
7
4
|
|
8
|
-
|
9
|
-
File.read file_with_contract
|
10
|
-
end
|
5
|
+
set :port, Contracto::Constants::PORT
|
11
6
|
|
12
|
-
|
13
|
-
|
14
|
-
|
7
|
+
get '/contracto' do
|
8
|
+
"*** Contracto server is working! [#{Gem::Specification.find_by_name('contracto').version}] ***"
|
9
|
+
end
|
10
|
+
|
11
|
+
jsons_with_contracts = Dir["#{Contracto::Config.root_dir}/**/*.con.json"].map do |file_with_contract|
|
12
|
+
File.read file_with_contract
|
13
|
+
end
|
14
|
+
|
15
|
+
Contracto::Parser.new(jsons_with_contracts).contracts.each do |contract|
|
16
|
+
send(contract.http_method, contract.url_pattern) do
|
17
|
+
contract.response_body(params)
|
18
|
+
end
|
15
19
|
end
|
16
|
-
end
|
17
20
|
|
21
|
+
end
|
18
22
|
|
@@ -21,15 +21,29 @@ class Contracto::SystemAction
|
|
21
21
|
def start_server
|
22
22
|
raise Contracto::ServerAlreadyRunningError if server_already_running?
|
23
23
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
24
|
+
require_relative 'server/ruby/server'
|
25
|
+
require 'daemons'
|
26
|
+
|
27
|
+
options = {
|
28
|
+
app_name: server_pidfile_name,
|
29
|
+
dir: Contracto::Config.root_dir,
|
30
|
+
dir_mode: :normal
|
31
|
+
}
|
32
|
+
|
33
|
+
Daemons.call(options) do
|
34
|
+
Contracto::Server.run!
|
35
|
+
end
|
36
|
+
|
37
|
+
5.downto(0).each do |n|
|
38
|
+
sleep 1
|
39
|
+
puts "waiting for contracto server, #{n} tries left..."
|
40
|
+
break if test_request(silent: true)
|
41
|
+
end
|
28
42
|
end
|
29
43
|
|
30
44
|
def stop_server
|
31
45
|
puts 'killing server...'
|
32
|
-
Process.kill(15, File.read(
|
46
|
+
Process.kill(15, File.read("#{Contracto::Config.root_dir}/#{server_pidfile_name}.pid").to_i)
|
33
47
|
puts '...server killed'
|
34
48
|
rescue Errno::ENOENT
|
35
49
|
puts 'could not kill server (pidfile not found)'
|
@@ -60,7 +74,7 @@ class Contracto::SystemAction
|
|
60
74
|
end
|
61
75
|
|
62
76
|
def contract_already_exists?
|
63
|
-
File.exist?("#{root_dir}/#{contract_filename}")
|
77
|
+
File.exist?("#{Contracto::Config.root_dir}/#{contract_filename}")
|
64
78
|
end
|
65
79
|
|
66
80
|
def server_already_running?
|
data/lib/contracto/version.rb
CHANGED
data/lib/contracto.rb
CHANGED
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.4.
|
4
|
+
version: 0.4.1
|
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-04-
|
11
|
+
date: 2015-04-16 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: daemons
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.2'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.2'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: rspec
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|