servitude 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.
@@ -13,21 +13,15 @@ module Servitude
13
13
  l.adapter $stdout, :level => [:debug, :info, :warn]
14
14
  l.adapter $stderr, :level => [:error, :fatal]
15
15
  end
16
-
17
- #Celluloid.logger = Yell.new do |l|
18
- #l.level = :info
19
- #l.adapter :file, File.join( File.dirname( options[:log] ), "#{APP_ID}-celluloid.log" )
20
- #end
21
16
  end
22
17
 
23
18
  def log_startup
24
- start_banner( options ).each do |line|
19
+ start_banner.each do |line|
25
20
  Servitude::NS.logger.info line
26
21
  end
27
22
  end
28
23
 
29
- def start_banner( options )
30
- configuration_attributes = Servitude::NS::Configuration.attributes rescue nil
24
+ def start_banner
31
25
  [
32
26
  "",
33
27
  "***",
@@ -35,46 +29,62 @@ module Servitude
35
29
  "*",
36
30
  "* #{Servitude::NS::VERSION_COPYRIGHT}",
37
31
  "*",
38
- "* Configuration:",
39
- (options[:config_loaded] ? "* file: #{options[:config]}" : nil),
40
- Array( configuration_attributes ).map { |a| "* #{a}: #{config_value a}" },
41
- "*",
32
+ (Servitude::NS::configuration.empty? ? nil : "* Configuration"),
33
+ PrettyPrint::configuration_lines( Servitude::NS::configuration, "* ", all_config_filters ),
34
+ (Servitude::NS::configuration.empty? ? nil : "*"),
42
35
  "***",
43
36
  ].flatten.reject( &:nil? )
44
37
  end
45
38
 
46
39
  def log_level
47
- options.fetch( :log_level, :info ).to_sym
40
+ ((Servitude::NS::configuration.log_level || :info).to_sym rescue :info)
48
41
  end
49
42
 
43
+ def all_config_filters
44
+ default_config_filters + config_filters
45
+ end
50
46
 
51
- def config_value( key )
52
- value = Servitude::NS.configuration.send( key )
53
-
54
- return value unless value.is_a?( Hash )
47
+ def default_config_filters
48
+ %w(
49
+ help
50
+ interactive
51
+ interactive_given
52
+ )
53
+ end
55
54
 
56
- return redacted_hash( value )
55
+ # Override for custom config filtering
56
+ #
57
+ def config_filters
58
+ []
57
59
  end
58
60
 
59
- def redacted_hash( hash )
60
- redacted_hash = {}
61
+ #def config_value( key )
62
+ #value = Servitude::NS.configuration.send( key )
61
63
 
62
- hash.keys.
63
- collect( &:to_s ).
64
- grep( /#{redacted_keys}/i ).
65
- each do |blacklisted_key|
66
- value = hash[blacklisted_key]
67
- redacted_hash[blacklisted_key] = value.nil? ? nil : '[REDACTED]'
68
- end
64
+ #return value unless value.is_a?( Hash )
69
65
 
70
- hash.merge( redacted_hash )
71
- end
66
+ #return redacted_hash( value )
67
+ #end
72
68
 
73
- def redacted_keys
74
- %w(
75
- password
76
- ).join( '|' )
77
- end
69
+ #def redacted_hash( hash )
70
+ #redacted_hash = {}
71
+
72
+ #hash.keys.
73
+ #collect( &:to_s ).
74
+ #grep( /#{redacted_keys}/i ).
75
+ #each do |blacklisted_key|
76
+ #value = hash[blacklisted_key]
77
+ #redacted_hash[blacklisted_key] = value.nil? ? nil : '[REDACTED]'
78
+ #end
79
+
80
+ #hash.merge( redacted_hash )
81
+ #end
82
+
83
+ #def redacted_keys
84
+ #%w(
85
+ #password
86
+ #).join( '|' )
87
+ #end
78
88
 
79
89
  end
80
90
  end
@@ -1,3 +1,3 @@
1
1
  module Servitude
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
data/servitude.gemspec CHANGED
@@ -21,8 +21,10 @@ Gem::Specification.new do |spec|
21
21
  spec.add_development_dependency "bundler", "~> 1.5"
22
22
  spec.add_development_dependency "pry-debugger"
23
23
  spec.add_development_dependency "rake"
24
+ spec.add_development_dependency "rspec"
24
25
 
25
26
  spec.add_dependency "celluloid", "~> 0"
27
+ spec.add_dependency "hashie"
26
28
  spec.add_dependency "hooks", "~> 0"
27
29
  spec.add_dependency "oj", "~> 2"
28
30
  spec.add_dependency "rainbow", "~> 2"
@@ -0,0 +1,71 @@
1
+ require "servitude/pretty_print"
2
+
3
+ describe Servitude::PrettyPrint do
4
+
5
+ describe '.configuration_lines' do
6
+ def configuration_lines( *arguments )
7
+ described_class.configuration_lines( *arguments )
8
+ end
9
+
10
+ describe 'a key-value pair' do
11
+ specify {
12
+ expect( configuration_lines( foo: 'bar' )).to eq( ["foo: bar"] )
13
+ }
14
+ end
15
+
16
+ describe 'multiple key-value pair' do
17
+ specify {
18
+ expect( configuration_lines( foo: 'bar', baz: 'bam' )).to eq( ["foo: bar", "baz: bam"] )
19
+ }
20
+ end
21
+
22
+ describe 'a nested key-value pair' do
23
+ specify {
24
+ expect( configuration_lines({ foo: { 'bar' => 'baz' } })).to eq( ["foo.bar: baz"] )
25
+ }
26
+ end
27
+
28
+ describe 'a nested config with an array' do
29
+ specify {
30
+ expect( configuration_lines({ foo: { 'bar' => 'baz', bam: [1,2,3] } })).to eq( ["foo.bar: baz", "foo.bam: [1, 2, 3]"] )
31
+ }
32
+ end
33
+
34
+ describe 'a nested config with an array with filter apilied' do
35
+ specify {
36
+ expect( configuration_lines({ foo: { 'bar' => 'baz', bam: [1,2,3] } }, '', %w(foo.bam))).to eq( ["foo.bar: baz"] )
37
+ }
38
+ end
39
+ end
40
+
41
+ describe '.format_configuration' do
42
+ def format_configuration( *arguments )
43
+ described_class.format_configuration( *arguments )
44
+ end
45
+
46
+ describe 'a key-value pair' do
47
+ specify {
48
+ expect( format_configuration( foo: 'bar' )).to eq( [["foo", "bar"]] )
49
+ }
50
+ end
51
+
52
+ describe 'multiple key-value pair' do
53
+ specify {
54
+ expect( format_configuration( foo: 'bar', baz: 'bam' )).to eq( [["foo","bar"],["baz","bam"]] )
55
+ }
56
+ end
57
+
58
+ describe 'a nested key-value pair' do
59
+ specify {
60
+ expect( format_configuration({ foo: { 'bar' => 'baz' } })).to eq( [["foo.bar", "baz"]] )
61
+ }
62
+ end
63
+
64
+ describe 'a nested config with an array' do
65
+ specify {
66
+ expect( format_configuration({ foo: { 'bar' => 'baz', bam: [1,2,3] } })).to eq( [["foo.bar", "baz"], ["foo.bam", "[1, 2, 3]"]] )
67
+ }
68
+ end
69
+ end
70
+
71
+ end
@@ -0,0 +1,89 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # The generated `.rspec` file contains `--require spec_helper` which will cause this
4
+ # file to always be loaded, without a need to explicitly require it in any files.
5
+ #
6
+ # Given that it is always loaded, you are encouraged to keep this file as
7
+ # light-weight as possible. Requiring heavyweight dependencies from this file
8
+ # will add to the boot time of your test suite on EVERY test run, even for an
9
+ # individual file that may not need all of that loaded. Instead, consider making
10
+ # a separate helper file that requires the additional dependencies and performs
11
+ # the additional setup, and require it from the spec files that actually need it.
12
+ #
13
+ # The `.rspec` file also contains a few flags that are not defaults but that
14
+ # users commonly want.
15
+ #
16
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
17
+ RSpec.configure do |config|
18
+ # rspec-expectations config goes here. You can use an alternate
19
+ # assertion/expectation library such as wrong or the stdlib/minitest
20
+ # assertions if you prefer.
21
+ config.expect_with :rspec do |expectations|
22
+ # This option will default to `true` in RSpec 4. It makes the `description`
23
+ # and `failure_message` of custom matchers include text for helper methods
24
+ # defined using `chain`, e.g.:
25
+ # be_bigger_than(2).and_smaller_than(4).description
26
+ # # => "be bigger than 2 and smaller than 4"
27
+ # ...rather than:
28
+ # # => "be bigger than 2"
29
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
30
+ end
31
+
32
+ # rspec-mocks config goes here. You can use an alternate test double
33
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
34
+ config.mock_with :rspec do |mocks|
35
+ # Prevents you from mocking or stubbing a method that does not exist on
36
+ # a real object. This is generally recommended, and will default to
37
+ # `true` in RSpec 4.
38
+ mocks.verify_partial_doubles = true
39
+ end
40
+
41
+ # The settings below are suggested to provide a good initial experience
42
+ # with RSpec, but feel free to customize to your heart's content.
43
+ =begin
44
+ # These two settings work together to allow you to limit a spec run
45
+ # to individual examples or groups you care about by tagging them with
46
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
47
+ # get run.
48
+ config.filter_run :focus
49
+ config.run_all_when_everything_filtered = true
50
+
51
+ # Limits the available syntax to the non-monkey patched syntax that is recommended.
52
+ # For more details, see:
53
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
54
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
55
+ # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
56
+ config.disable_monkey_patching!
57
+
58
+ # This setting enables warnings. It's recommended, but in some cases may
59
+ # be too noisy due to issues in dependencies.
60
+ config.warnings = true
61
+
62
+ # Many RSpec users commonly either run the entire suite or an individual
63
+ # file, and it's useful to allow more verbose output when running an
64
+ # individual spec file.
65
+ if config.files_to_run.one?
66
+ # Use the documentation formatter for detailed output,
67
+ # unless a formatter has already been configured
68
+ # (e.g. via a command-line flag).
69
+ config.default_formatter = 'doc'
70
+ end
71
+
72
+ # Print the 10 slowest examples and example groups at the
73
+ # end of the spec run, to help surface which specs are running
74
+ # particularly slow.
75
+ config.profile_examples = 10
76
+
77
+ # Run specs in random order to surface order dependencies. If you find an
78
+ # order dependency and want to debug it, you can fix the order by providing
79
+ # the seed, which is printed after each run.
80
+ # --seed 1234
81
+ config.order = :random
82
+
83
+ # Seed global randomization in this process using the `--seed` CLI option.
84
+ # Setting this allows you to use `--seed` to deterministically reproduce
85
+ # test failures related to randomization by passing the same `--seed` value
86
+ # as the one that triggered the failure.
87
+ Kernel.srand config.seed
88
+ =end
89
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: servitude
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
  - Jason Harrelson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-11 00:00:00.000000000 Z
11
+ date: 2014-09-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: celluloid
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -66,6 +80,20 @@ dependencies:
66
80
  - - "~>"
67
81
  - !ruby/object:Gem::Version
68
82
  version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: hashie
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
69
97
  - !ruby/object:Gem::Dependency
70
98
  name: hooks
71
99
  requirement: !ruby/object:Gem::Requirement
@@ -145,27 +173,39 @@ extensions: []
145
173
  extra_rdoc_files: []
146
174
  files:
147
175
  - ".gitignore"
176
+ - ".rspec"
148
177
  - ".ruby-gemset"
149
178
  - ".ruby-version"
150
179
  - Gemfile
151
180
  - LICENSE.txt
152
181
  - README.md
153
182
  - Rakefile
183
+ - config/4.conf
184
+ - config/5.conf
154
185
  - examples/1_simple_server
155
186
  - examples/2_echo_server
187
+ - examples/3_echo_server_with_cli_and_daemon
188
+ - examples/4_echo_server_with_cli_daemon_and_file_config
189
+ - examples/5_echo_server_with_cli_daemon_and_env_config
156
190
  - lib/servitude.rb
157
191
  - lib/servitude/actor.rb
158
192
  - lib/servitude/base.rb
159
193
  - lib/servitude/cli.rb
194
+ - lib/servitude/config_helper.rb
160
195
  - lib/servitude/configuration.rb
161
196
  - lib/servitude/daemon.rb
197
+ - lib/servitude/environment_configuration.rb
162
198
  - lib/servitude/logging.rb
199
+ - lib/servitude/pretty_print.rb
163
200
  - lib/servitude/server.rb
164
201
  - lib/servitude/server_logging.rb
165
202
  - lib/servitude/server_threaded.rb
166
203
  - lib/servitude/supervision_error.rb
167
204
  - lib/servitude/version.rb
168
205
  - servitude.gemspec
206
+ - spec/servitude/pretty_print_spec.rb
207
+ - spec/spec_helper.rb
208
+ - tmp/.gitkeep
169
209
  homepage: ''
170
210
  licenses:
171
211
  - MIT
@@ -191,4 +231,6 @@ signing_key:
191
231
  specification_version: 4
192
232
  summary: A set of utilities to aid in building multithreaded Ruby servers utilizing
193
233
  Celluloid.
194
- test_files: []
234
+ test_files:
235
+ - spec/servitude/pretty_print_spec.rb
236
+ - spec/spec_helper.rb