community-zero 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6365dd0adfe1bee925f49a26bc815a1711539134
4
+ data.tar.gz: 944715fb62f1c8e301885deb15648fa30848e99e
5
+ SHA512:
6
+ metadata.gz: c5743a126349eb8994ee3fba8a34223e678d77162ddcbc9ea799c9585bbc065d7ad531651b0c9c51ca7913929b51b4a86f2f309b2b6f4b27ed3bfcacca204b30
7
+ data.tar.gz: 89a55c0ef618d29ea06ee05c2c94e622a9b9abd45490f671b9ff32bd5885692d586cc8749c909a75fa5b40f01f42a1ff6503e3a227e8056285c63d2df0fb37d3
data/README.md CHANGED
@@ -1,7 +1,9 @@
1
1
  Community Zero
2
2
  ==============
3
- [![Code Climate](https://codeclimate.com/github/sethvargo/community-zero.png)](https://codeclimate.com/github/sethvargo/community-zero)
3
+ [![Gem Version](https://badge.fury.io/rb/community-zero.png)](http://badge.fury.io/rb/community-zero)
4
4
  [![Build Status](https://travis-ci.org/sethvargo/community-zero.png?branch=master)](https://travis-ci.org/sethvargo/community-zero)
5
+ [![Dependency Status](https://gemnasium.com/sethvargo/community-zero.png)](https://gemnasium.com/sethvargo/community-zero)
6
+ [![Code Climate](https://codeclimate.com/github/sethvargo/community-zero.png)](https://codeclimate.com/github/sethvargo/community-zero)
5
7
 
6
8
  Description
7
9
  -----------
@@ -35,6 +35,10 @@ OptionParser.new do |opts|
35
35
  options[:port] = value
36
36
  end
37
37
 
38
+ opts.on('-s', '--socket SOCK', String, 'Unix socket path to listen on') do |value|
39
+ options[:socket] = value
40
+ end
41
+
38
42
  opts.on('-l', '--log-level LEVEL', 'Set the output log level') do |value|
39
43
  options[:log_level] = value
40
44
  end
@@ -17,15 +17,16 @@
17
17
 
18
18
  require 'json'
19
19
  require 'puma'
20
+ require 'timeout'
20
21
 
21
22
  module CommunityZero
22
- require 'community_zero/chef'
23
- require 'community_zero/endpoint'
24
- require 'community_zero/error'
25
- require 'community_zero/object'
26
- require 'community_zero/request'
27
- require 'community_zero/router'
28
- require 'community_zero/server'
29
- require 'community_zero/store'
30
- require 'community_zero/version'
23
+ require_relative 'community_zero/chef'
24
+ require_relative 'community_zero/endpoint'
25
+ require_relative 'community_zero/error'
26
+ require_relative 'community_zero/object'
27
+ require_relative 'community_zero/request'
28
+ require_relative 'community_zero/router'
29
+ require_relative 'community_zero/server'
30
+ require_relative 'community_zero/store'
31
+ require_relative 'community_zero/version'
31
32
  end
@@ -16,5 +16,5 @@
16
16
  #
17
17
 
18
18
  module CommunityZero
19
- require 'community_zero/chef/metadata'
19
+ require_relative 'chef/metadata'
20
20
  end
@@ -20,11 +20,11 @@ module CommunityZero
20
20
  #
21
21
  # @author Seth Vargo <sethvargo@gmail.com>
22
22
  class Endpoint
23
- require 'community_zero/endpoints/cookbook_endpoint'
24
- require 'community_zero/endpoints/cookbook_versions_version_endpoint'
25
- require 'community_zero/endpoints/cookbooks_endpoint'
26
- require 'community_zero/endpoints/not_found_endpoint'
27
- require 'community_zero/endpoints/search_endpoint'
23
+ require_relative 'endpoints/cookbook_endpoint'
24
+ require_relative 'endpoints/cookbook_versions_version_endpoint'
25
+ require_relative 'endpoints/cookbooks_endpoint'
26
+ require_relative 'endpoints/not_found_endpoint'
27
+ require_relative 'endpoints/search_endpoint'
28
28
 
29
29
  METHODS = [:get, :put, :post, :delete].freeze
30
30
 
@@ -21,5 +21,5 @@ module CommunityZero
21
21
  # @author Seth Vargo <sethvargo@gmail.com>
22
22
  class Error < StandardError; end
23
23
 
24
- require 'community_zero/errors/rest_error'
24
+ require_relative 'errors/rest_error'
25
25
  end
@@ -20,6 +20,6 @@ module CommunityZero
20
20
  #
21
21
  # @author Seth Vargo <sethvargo@gmail.com>
22
22
  class Object
23
- require 'community_zero/objects/cookbook'
23
+ require_relative 'objects/cookbook'
24
24
  end
25
25
  end
@@ -18,7 +18,7 @@
18
18
  module CommunityZero
19
19
  # A singleton request.
20
20
  #
21
- # @author Seth Vargon <sethvargo@gmail.com>
21
+ # @author Seth Vargo <sethvargo@gmail.com>
22
22
  class Request
23
23
  attr_reader :env
24
24
 
@@ -20,7 +20,7 @@ module CommunityZero
20
20
  #
21
21
  # @author Seth Vargo <sethvargo@gmail.com>
22
22
  class Router
23
- require 'community_zero/endpoint'
23
+ require_relative 'endpoint'
24
24
 
25
25
  attr_reader :server, :routes
26
26
 
@@ -20,7 +20,7 @@ module CommunityZero
20
20
  #
21
21
  # @author Seth Vargo <sethvargo@gmail.com>
22
22
  class Server
23
- require 'community_zero'
23
+ require_relative '../community_zero'
24
24
 
25
25
  DEFAULT_OPTIONS = {
26
26
  :host => '0.0.0.0',
@@ -51,9 +51,11 @@ module CommunityZero
51
51
  # the thread the server is running in
52
52
  def start
53
53
  if options[:publish]
54
- puts ">> Starting Community Zero (v#{CommunityZero::VERSION})..."
55
- puts ">> Puma (v#{Puma::Const::PUMA_VERSION}) is listening at #{url}"
56
- puts ">> Press CTRL+C to stop"
54
+ puts [
55
+ ">> Starting Community Zero (v#{CommunityZero::VERSION})...",
56
+ ">> Puma (v#{Puma::Const::PUMA_VERSION}) is listening at #{url}",
57
+ ">> Press CTRL+C to stop",
58
+ ].join("\n")
57
59
  end
58
60
 
59
61
  begin
@@ -64,12 +66,64 @@ module CommunityZero
64
66
  end
65
67
  end
66
68
 
69
+ # Start the community server as a background process in a Thread.
70
+ # This is useful when using CommunityZero as a testing server with RSpec.
71
+ #
72
+ # @param [Fixnum] wait
73
+ # the number of seconds to wait for the server to start
74
+ #
75
+ # @return [Thread]
76
+ # the thread the server is running in
77
+ def start_background(wait = 5)
78
+ @thread = Thread.new do
79
+ begin
80
+ start
81
+ rescue
82
+ @server_error = $!
83
+ $stderr.puts "#{$!.message}\n#{$!.backtrace.join("\n")}"
84
+ end
85
+ end
86
+
87
+ Timeout::timeout(wait) do
88
+ sleep(0.01) until running? || @server_error
89
+ raise @server_error if @server_error
90
+ end
91
+
92
+ @thread
93
+ end
94
+
67
95
  # Determine if the server is currently running.
68
96
  #
69
97
  # @return [Boolean]
70
98
  # true if the server is currently running, false otherwise
71
99
  def running?
72
- server && server.running?
100
+ # NOTE: we intentionally use the instance variable here, otherwise
101
+ # there are race conditions because calling {server} would actually
102
+ # start the server unintentionally.
103
+ !!(@server && @server.running)
104
+ end
105
+
106
+ # Stop the running server.
107
+ #
108
+ # @param [Fixnum] wait
109
+ # the number of seconds to wait for the server to stop
110
+ def stop(wait = 5)
111
+ if @thread
112
+ @thread.join(wait)
113
+ else
114
+ server.stop(true)
115
+ end
116
+ rescue
117
+ $stderr.puts "Server did not stop within #{wait} seconds. Killing..."
118
+ @thread.kill if @thread
119
+ ensure
120
+ @thread = nil
121
+ end
122
+
123
+ # Clear out any existing entires and reset the server's contents to a
124
+ # clean state.
125
+ def reset!
126
+ CommunityZero::Store.destroy_all
73
127
  end
74
128
 
75
129
  # Returns the URL the server is listening on.
@@ -94,7 +148,13 @@ module CommunityZero
94
148
  return @server if @server
95
149
 
96
150
  @server = Puma::Server.new(app, Puma::Events.new(STDERR, STDOUT))
97
- @server.add_tcp_listener(options[:host], options[:port])
151
+
152
+ if options[:socket]
153
+ @server.add_unix_listener(options[:socket])
154
+ else
155
+ @server.add_tcp_listener(options[:host], options[:port])
156
+ end
157
+
98
158
  @server
99
159
  end
100
160
 
@@ -16,5 +16,5 @@
16
16
  #
17
17
 
18
18
  module CommunityZero
19
- VERSION = '1.0.0'
19
+ VERSION = '1.1.0'
20
20
  end
metadata CHANGED
@@ -1,20 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: community-zero
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
5
- prerelease:
4
+ version: 1.1.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Seth Vargo
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-06-04 00:00:00.000000000 Z
11
+ date: 2013-08-21 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: puma
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - ~>
20
18
  - !ruby/object:Gem::Version
@@ -22,7 +20,6 @@ dependencies:
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
24
  - - ~>
28
25
  - !ruby/object:Gem::Version
@@ -30,7 +27,6 @@ dependencies:
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: cucumber
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
31
  - - ~>
36
32
  - !ruby/object:Gem::Version
@@ -38,7 +34,6 @@ dependencies:
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
38
  - - ~>
44
39
  - !ruby/object:Gem::Version
@@ -46,7 +41,6 @@ dependencies:
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: json_spec
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
45
  - - ~>
52
46
  - !ruby/object:Gem::Version
@@ -54,7 +48,6 @@ dependencies:
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
52
  - - ~>
60
53
  - !ruby/object:Gem::Version
@@ -62,7 +55,6 @@ dependencies:
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: rack-test
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
59
  - - ~>
68
60
  - !ruby/object:Gem::Version
@@ -70,7 +62,6 @@ dependencies:
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
66
  - - ~>
76
67
  - !ruby/object:Gem::Version
@@ -78,7 +69,6 @@ dependencies:
78
69
  - !ruby/object:Gem::Dependency
79
70
  name: rspec
80
71
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
72
  requirements:
83
73
  - - ~>
84
74
  - !ruby/object:Gem::Version
@@ -86,7 +76,6 @@ dependencies:
86
76
  type: :development
87
77
  prerelease: false
88
78
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
79
  requirements:
91
80
  - - ~>
92
81
  - !ruby/object:Gem::Version
@@ -123,27 +112,26 @@ files:
123
112
  - bin/community-zero
124
113
  homepage: https://github.com/sethvargo/community-zero
125
114
  licenses: []
115
+ metadata: {}
126
116
  post_install_message:
127
117
  rdoc_options: []
128
118
  require_paths:
129
119
  - lib
130
120
  required_ruby_version: !ruby/object:Gem::Requirement
131
- none: false
132
121
  requirements:
133
- - - ! '>='
122
+ - - '>='
134
123
  - !ruby/object:Gem::Version
135
124
  version: '0'
136
125
  required_rubygems_version: !ruby/object:Gem::Requirement
137
- none: false
138
126
  requirements:
139
- - - ! '>='
127
+ - - '>='
140
128
  - !ruby/object:Gem::Version
141
129
  version: '0'
142
130
  requirements: []
143
131
  rubyforge_project:
144
- rubygems_version: 1.8.23
132
+ rubygems_version: 2.0.3
145
133
  signing_key:
146
- specification_version: 3
134
+ specification_version: 4
147
135
  summary: Self-contained, easy-setup, fast-start in-memory Chef Community Site for
148
136
  testing.
149
137
  test_files: []