dry-web 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4cf74e9914404859f3cf1f5b28876932a39d0117
4
- data.tar.gz: 9dd040e94f0c465f88c9801ca374286b07b47a6e
3
+ metadata.gz: ebcf4adb58017f9e639efb394e9beffed9569647
4
+ data.tar.gz: 04635ad8ebd204c99a9b07cd058c5153d72ac688
5
5
  SHA512:
6
- metadata.gz: 903895a3b8da46407d8a852c6b2aebbeb1b4497cece24c8887d88b5ccfa88dfb4b2f80a8acd0f31813d22fe743ab64afa7ee220aeb96133a382ac8ea88a8891e
7
- data.tar.gz: 4c724b2eade0233c437fc6abdeef5d3d862f0404fbad4615ddbc1d56414154771752d77de1ea9db1e777a647a591236fbd8dfad490bc62274473aca0b4571355
6
+ metadata.gz: b66229021044639a2abe4d42d4f4728deed718cd774324f1b551a8ebd6ef1c533f5bd4a7720753ada38c135ade1a47aaf9fcb4814cd8a6a621d2fa8d764b31bb
7
+ data.tar.gz: 2095506487f2aafa110dc75eba1dd202fd8a6ab9fadefafc5885e628dba7fb4aab8d80a3339d3080f22530d18b958d773005a5d1401d54b05f6a40857eda7149
data/.travis.yml CHANGED
@@ -1,24 +1,21 @@
1
1
  language: ruby
2
- sudo: false
2
+ dist: trusty
3
+ sudo: required
3
4
  cache: bundler
4
5
  bundler_args: --without tools
5
6
  script:
6
7
  - bundle exec rake spec
8
+ after_script:
9
+ - bundle exec codeclimate-test-reporter
7
10
  rvm:
8
11
  - 2.1
9
12
  - 2.2
10
13
  - 2.3.0
11
- - rbx-2
14
+ - rbx-3
12
15
  - jruby-9000
13
- - ruby-head
14
- - jruby-head
15
16
  env:
16
17
  global:
17
18
  - JRUBY_OPTS='--dev -J-Xmx1024M'
18
- matrix:
19
- allow_failures:
20
- - rvm: ruby-head
21
- - rvm: jruby-head
22
19
  notifications:
23
20
  email: false
24
21
  webhooks:
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ # 0.6.0 - 2017-02-02
2
+
3
+ ### Added
4
+
5
+ * Support for [dry-monitor](https://github.com/dry-rb/dry-monitor) with notifications and rack logging (solnic)
6
+
1
7
  # 0.5.0 - 2016-08-15
2
8
 
3
9
  Update to work with dry-system
data/Gemfile CHANGED
@@ -5,6 +5,7 @@ gemspec
5
5
  group :test do
6
6
  gem 'byebug', platform: :mri
7
7
  gem 'codeclimate-test-reporter'
8
+ gem 'rack'
8
9
  end
9
10
 
10
11
  group :tools do
data/README.md CHANGED
@@ -11,32 +11,18 @@
11
11
  [![Test Coverage](https://codeclimate.com/github/dry-rb/dry-web/badges/coverage.svg)][codeclimate]
12
12
  [![Inline docs](http://inch-ci.org/github/dry-rb/dry-web.svg?branch=master&style=flat)][inchpages]
13
13
 
14
- ## Tools
14
+ ## Examples
15
15
 
16
- dry-web is composed from the following libraries:
17
-
18
- * [dry-component](https://github.com/dry-rb/dry-component)
16
+ See [icelab/berg](https://github.com/icelab/berg) for a working dry-web app, using [dry-web-roda](https://github.com/dry-rb/dry-web-roda).
19
17
 
20
18
  ## LICENSE
21
19
 
22
- See `LICENSE.txt` file.
20
+ See `LICENSE` file.
23
21
 
24
22
  ## Development
25
23
 
26
- To run the specs make sure the dummy app uses proper db configuration `spec/dummy/config/application.yml`.
27
- Also you need to run the migrations, do following:
28
-
29
- ```
30
- $ cd spec/dummy
31
- $ bundle install
32
- $ rake db:migrate
33
- ```
34
-
35
- After that you can run the specs from dry-web root:
36
-
37
- ```
38
- $ bundle exec rspec
39
- ```
24
+ After checking out the repo, run `bundle install` to install dependencies. Then, run
25
+ `bundle exec rake spec` to run the tests.
40
26
 
41
27
  ## Contributing
42
28
 
data/dry-web.gemspec CHANGED
@@ -8,7 +8,7 @@ Gem::Specification.new do |spec|
8
8
  spec.version = Dry::Web::VERSION
9
9
  spec.authors = ["Piotr Solnica"]
10
10
  spec.email = ["piotr.solnica@gmail.com"]
11
- spec.summary = "Lightweight web application stack on top of dry-component"
11
+ spec.summary = "Lightweight web application stack on top of dry-system"
12
12
  spec.description = spec.summary
13
13
  spec.homepage = "https://github.com/dry-rb/dry-web"
14
14
  spec.license = "MIT"
@@ -21,6 +21,7 @@ Gem::Specification.new do |spec|
21
21
  spec.required_ruby_version = '>= 2.1.0'
22
22
 
23
23
  spec.add_runtime_dependency "dry-system", "~> 0.5"
24
+ spec.add_runtime_dependency "dry-monitor"
24
25
 
25
26
  spec.add_development_dependency "bundler", "~> 1.7"
26
27
  spec.add_development_dependency "rake", "~> 11.0"
@@ -1,9 +1,56 @@
1
1
  require 'dry/system/container'
2
+ require 'dry/monitor'
2
3
 
3
4
  module Dry
4
5
  module Web
5
6
  class Container < Dry::System::Container
6
7
  setting :env, ENV.fetch('RACK_ENV', 'development').to_sym
8
+ setting :log_dir, 'log'.freeze
9
+ setting :log_levels, development: Logger::DEBUG
10
+ setting :logger
11
+ setting :listeners, false
12
+
13
+ class << self
14
+ def configure(&block)
15
+ super.
16
+ configure_logger.
17
+ configure_notifications.
18
+ configure_rack_monitor.
19
+ attach_listeners
20
+ end
21
+
22
+ def configure_logger
23
+ if key?(:logger)
24
+ self
25
+ elsif config.logger
26
+ register(:logger, config.logger)
27
+ else
28
+ config.logger = Monitor::Logger.new(config.root.join(config.log_dir).realpath.join("#{config.env}.log"))
29
+ config.logger.level = config.log_levels.fetch(config.env, Logger::ERROR)
30
+ register(:logger, config.logger)
31
+ self
32
+ end
33
+ end
34
+
35
+ def configure_notifications
36
+ return self if key?(:notifications)
37
+ register(:notifications, Monitor::Notifications.new(config.name))
38
+ self
39
+ end
40
+
41
+ def configure_rack_monitor
42
+ return self if key?(:rack_monitor)
43
+ register(:rack_monitor, Monitor::Rack::Middleware.new(self[:notifications]))
44
+ self
45
+ end
46
+
47
+ def attach_listeners
48
+ return unless config.listeners
49
+ rack_logger = Monitor::Rack::Logger.new(self[:logger])
50
+ rack_logger.attach(self[:rack_monitor])
51
+ self
52
+ end
53
+ end
7
54
  end
8
55
  end
9
56
  end
@@ -1,5 +1,5 @@
1
1
  module Dry
2
2
  module Web
3
- VERSION = '0.5.0'.freeze
3
+ VERSION = '0.6.0'.freeze
4
4
  end
5
5
  end
data/log/.gitkeep ADDED
File without changes
File without changes
data/spec/spec_helper.rb CHANGED
@@ -1,9 +1,6 @@
1
1
  ENV["RACK_ENV"] = "test"
2
2
 
3
3
  if RUBY_ENGINE == "ruby"
4
- require "codeclimate-test-reporter"
5
- CodeClimate::TestReporter.start
6
-
7
4
  require "simplecov"
8
5
  SimpleCov.start do
9
6
  add_filter "/spec/"
@@ -1,5 +1,5 @@
1
1
  RSpec.describe "Dry::Web::Container" do
2
- subject(:container) { Dry::Web::Container }
2
+ subject(:container) { Class.new(Dry::Web::Container) }
3
3
 
4
4
  describe "settings" do
5
5
  # Do some acrobatics to make the container reload a setting from scratch
@@ -9,10 +9,76 @@ RSpec.describe "Dry::Web::Container" do
9
9
  Dry::Web::Container.remove_instance_variable(:@_config)
10
10
  end
11
11
 
12
- Dry::Web::Container.instance_variable_get(:@_settings)[key] = nil
12
+ Dry::Web::Container.instance_variable_get(:@_settings).delete_if do |setting|
13
+ setting.name == key
14
+ end
13
15
  load "dry/web/container.rb"
14
16
  end
15
17
 
18
+ describe ".config.logger" do
19
+ it 'sets up default logger for development env' do
20
+ container.configure do |config|
21
+ config.env = :development
22
+ end
23
+
24
+ expect(container[:logger].level).to be(Logger::DEBUG)
25
+ end
26
+
27
+ it 'sets up default logger for non-development env' do
28
+ container.configure do |config|
29
+ config.env = :production
30
+ end
31
+
32
+ expect(container[:logger].level).to be(Logger::ERROR)
33
+ end
34
+
35
+ it 'allows presetting a loggert' do
36
+ container.configure do |config|
37
+ config.logger = 'my logger'
38
+ end
39
+
40
+ expect(container[:logger]).to eql('my logger')
41
+ end
42
+ end
43
+
44
+ describe '.config.notifications' do
45
+ it 'sets up notifications by default' do
46
+ container.configure do |config|
47
+ config.env = :development
48
+ end
49
+
50
+ expect(container[:notifications].id).to be(container.config.name)
51
+ end
52
+ end
53
+
54
+ describe '.config.rack_monitor' do
55
+ it 'sets up rack monitor by default' do
56
+ container.configure do |config|
57
+ config.env = :development
58
+ end
59
+
60
+ expect(container[:rack_monitor].notifications).to be(container[:notifications])
61
+ end
62
+ end
63
+
64
+ describe '.config.rack_logger' do
65
+ it 'sets up rack logger by default' do
66
+ logger = spy(:logger)
67
+
68
+ container.configure do |config|
69
+ config.env = :development
70
+ config.logger = logger
71
+ config.listeners = true
72
+ end
73
+
74
+ payload = { a_rack: :env_hash }
75
+
76
+ container[:rack_monitor].instrument(:start, env: payload)
77
+
78
+ expect(logger).to have_received(:info)
79
+ end
80
+ end
81
+
16
82
  describe ".config.env" do
17
83
  context "existing RACK_ENV environment variable" do
18
84
  before do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dry-web
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Piotr Solnica
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-15 00:00:00.000000000 Z
11
+ date: 2017-02-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-system
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: dry-monitor
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: bundler
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -80,7 +94,7 @@ dependencies:
80
94
  - - "~>"
81
95
  - !ruby/object:Gem::Version
82
96
  version: 0.10.0
83
- description: Lightweight web application stack on top of dry-component
97
+ description: Lightweight web application stack on top of dry-system
84
98
  email:
85
99
  - piotr.solnica@gmail.com
86
100
  executables: []
@@ -91,10 +105,8 @@ files:
91
105
  - ".rspec"
92
106
  - ".travis.yml"
93
107
  - CHANGELOG.md
94
- - CODE_OF_CONDUCT.md
95
108
  - Gemfile
96
109
  - LICENSE
97
- - LICENSE.txt
98
110
  - README.md
99
111
  - Rakefile
100
112
  - dry-web.gemspec
@@ -104,7 +116,9 @@ files:
104
116
  - lib/dry/web/settings.rb
105
117
  - lib/dry/web/umbrella.rb
106
118
  - lib/dry/web/version.rb
119
+ - log/.gitkeep
107
120
  - spec/fixtures/test/config/settings.yml
121
+ - spec/fixtures/test/log/.gitkeep
108
122
  - spec/spec_helper.rb
109
123
  - spec/unit/container_spec.rb
110
124
  - spec/unit/settings_spec.rb
@@ -129,12 +143,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
129
143
  version: '0'
130
144
  requirements: []
131
145
  rubyforge_project:
132
- rubygems_version: 2.5.1
146
+ rubygems_version: 2.6.9
133
147
  signing_key:
134
148
  specification_version: 4
135
- summary: Lightweight web application stack on top of dry-component
149
+ summary: Lightweight web application stack on top of dry-system
136
150
  test_files:
137
151
  - spec/fixtures/test/config/settings.yml
152
+ - spec/fixtures/test/log/.gitkeep
138
153
  - spec/spec_helper.rb
139
154
  - spec/unit/container_spec.rb
140
155
  - spec/unit/settings_spec.rb
data/CODE_OF_CONDUCT.md DELETED
@@ -1,13 +0,0 @@
1
- # Contributor Code of Conduct
2
-
3
- As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
-
5
- We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
6
-
7
- Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
-
9
- Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
-
11
- Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
-
13
- This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/LICENSE.txt DELETED
@@ -1,22 +0,0 @@
1
- Copyright (c) 2015 Piotr Solnica
2
-
3
- MIT License
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining
6
- a copy of this software and associated documentation files (the
7
- "Software"), to deal in the Software without restriction, including
8
- without limitation the rights to use, copy, modify, merge, publish,
9
- distribute, sublicense, and/or sell copies of the Software, and to
10
- permit persons to whom the Software is furnished to do so, subject to
11
- the following conditions:
12
-
13
- The above copyright notice and this permission notice shall be
14
- included in all copies or substantial portions of the Software.
15
-
16
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.