ballast 2.2.3 → 2.2.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +3 -4
  3. data/.rubocop.yml +47 -5
  4. data/.travis.yml +6 -3
  5. data/CHANGELOG.md +4 -0
  6. data/Gemfile +2 -1
  7. data/README.md +0 -1
  8. data/Rakefile +17 -11
  9. data/ballast.gemspec +1 -1
  10. data/doc/Ballast.html +69 -1
  11. data/doc/Ballast/AjaxResponse.html +1 -1
  12. data/doc/Ballast/Concerns.html +1 -1
  13. data/doc/Ballast/Concerns/AjaxHandling.html +4 -4
  14. data/doc/Ballast/Concerns/Common.html +2 -2
  15. data/doc/Ballast/Concerns/ErrorsHandling.html +1 -1
  16. data/doc/Ballast/Concerns/View.html +1 -1
  17. data/doc/Ballast/Configuration.html +1 -1
  18. data/doc/Ballast/Emoji.html +1 -1
  19. data/doc/Ballast/Emoji/Character.html +1 -1
  20. data/doc/Ballast/Emoji/Utils.html +5 -5
  21. data/doc/Ballast/Errors.html +1 -1
  22. data/doc/Ballast/Errors/Base.html +1 -1
  23. data/doc/Ballast/Errors/Failure.html +1 -1
  24. data/doc/Ballast/Errors/InvalidDomain.html +1 -1
  25. data/doc/Ballast/Errors/ValidationFailure.html +1 -1
  26. data/doc/Ballast/Middlewares.html +1 -1
  27. data/doc/Ballast/Middlewares/DefaultHost.html +1 -1
  28. data/doc/Ballast/RequestDomainMatcher.html +1 -1
  29. data/doc/Ballast/Service.html +12 -12
  30. data/doc/Ballast/Service/Response.html +29 -29
  31. data/doc/Ballast/Version.html +2 -2
  32. data/doc/_index.html +1 -1
  33. data/doc/file.README.html +2 -3
  34. data/doc/index.html +2 -3
  35. data/doc/method_list.html +39 -33
  36. data/doc/top-level-namespace.html +1 -1
  37. data/lib/ballast.rb +0 -2
  38. data/lib/ballast/concerns/ajax_handling.rb +3 -3
  39. data/lib/ballast/concerns/common.rb +1 -1
  40. data/lib/ballast/configuration.rb +3 -1
  41. data/lib/ballast/emoji.rb +2 -2
  42. data/lib/ballast/service.rb +8 -8
  43. data/lib/ballast/version.rb +1 -1
  44. data/spec/ballast/concerns/common_spec.rb +1 -1
  45. data/spec/ballast/configuration_spec.rb +5 -3
  46. data/spec/ballast/service_spec.rb +12 -0
  47. data/spec/spec_helper.rb +18 -1
  48. metadata +3 -5
  49. data/spec/coverage_helper.rb +0 -19
@@ -103,7 +103,7 @@
103
103
  </div>
104
104
 
105
105
  <div id="footer">
106
- Generated on Wed Mar 9 10:37:56 2016 by
106
+ Generated on Tue Mar 29 10:52:51 2016 by
107
107
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
108
108
  0.8.7.6 (ruby-2.3.0).
109
109
  </div>
@@ -48,8 +48,6 @@ module Ballast
48
48
  end
49
49
  end
50
50
 
51
- private
52
-
53
51
  # :nodoc:
54
52
  def self.run_in_thread(&block)
55
53
  EM::Synchrony.defer do
@@ -58,14 +58,14 @@ module Ballast
58
58
  # @param configuration [Hash|NilClass] An hash of agent and list of paths to include.
59
59
  def generate_robots_txt(configuration = nil)
60
60
  configuration ||= {"*" => "/"}
61
- rv = configuration.reduce([]) { |accu, (agent, paths)|
61
+ rv = configuration.reduce([]) do |accu, (agent, paths)|
62
62
  paths = paths.ensure_array.map { |e| "Disallow: #{e}" }
63
63
 
64
64
  accu << "User-agent: #{agent}\n#{paths.join("\n")}"
65
65
  accu
66
- }.join("\n\n")
66
+ end
67
67
 
68
- render(text: rv, content_type: "text/plain")
68
+ render(text: rv.join("\n\n"), content_type: "text/plain")
69
69
  end
70
70
  alias_method :disallow_robots, :generate_robots_txt
71
71
  end
@@ -85,7 +85,7 @@ module Ballast
85
85
  # @param message [String|NilClass] A message for authentication errors.
86
86
  # @param authenticator [Proc] A block to verify if authentication is valid.
87
87
  def authenticate_user(area: nil, title: nil, message: nil, &authenticator)
88
- return if authenticate_with_http_basic { |username, password| authenticator.call(username, password) }
88
+ return if authenticate_with_http_basic(&authenticator)
89
89
 
90
90
  area ||= "Private Area"
91
91
  title ||= "Authentication required."
@@ -44,7 +44,9 @@ module Ballast
44
44
 
45
45
  # :nodoc:
46
46
  def load_section(root, section)
47
- YAML.load_file("#{root}/config/#{section}.yml") rescue {}
47
+ YAML.load_file("#{root}/config/#{section}.yml")
48
+ rescue
49
+ {}
48
50
  end
49
51
  end
50
52
  end
@@ -42,10 +42,10 @@ module Ballast
42
42
  keys_method = :markup unless keys_method && tester.respond_to?(keys_method)
43
43
  values_method = :html unless values_method && tester.respond_to?(values_method)
44
44
 
45
- ::Emoji.all.reduce({}) { |accu, icon|
45
+ ::Emoji.all.reduce({}) do |accu, icon|
46
46
  accu[invoke(icon, keys_method, options)] = invoke(icon, values_method, options)
47
47
  accu
48
- }
48
+ end
49
49
  end
50
50
 
51
51
  # Returns the URL mapper for the emojis.
@@ -65,13 +65,13 @@ module Ballast
65
65
  # @return [AjaxResponse] The AJAX response, which will include only the first error.
66
66
  def as_ajax_response(transport = nil)
67
67
  status, error_message =
68
- if successful?
69
- [:ok, nil]
70
- elsif error.is_a?(Hash)
71
- [error[:status], error[:error]]
72
- else
73
- [:unknown, error]
74
- end
68
+ if successful?
69
+ [:ok, nil]
70
+ elsif error.is_a?(Hash)
71
+ [error[:status], error[:error]]
72
+ else
73
+ [:unknown, error]
74
+ end
75
75
 
76
76
  AjaxResponse.new(status: status, data: data, error: error_message, transport: transport)
77
77
  end
@@ -98,7 +98,7 @@ module Ballast
98
98
  # Marks the failure of the operation.
99
99
  #
100
100
  # @param details [Object] The error(s) occurred.
101
- def self.fail!(details, on_validation: false)
101
+ def self.fail!(details)
102
102
  raise(Errors::Failure, details)
103
103
  end
104
104
 
@@ -16,7 +16,7 @@ module Ballast
16
16
  MINOR = 2
17
17
 
18
18
  # The patch version.
19
- PATCH = 3
19
+ PATCH = 4
20
20
 
21
21
  # The current version of ballast.
22
22
  STRING = [MAJOR, MINOR, PATCH].compact.join(".")
@@ -11,7 +11,7 @@ describe Ballast::Concerns::Common do
11
11
  end
12
12
 
13
13
  class CommonMockService < Ballast::Service
14
- def perform(params: params)
14
+ def perform(params: {})
15
15
  "OK"
16
16
  end
17
17
 
@@ -45,16 +45,18 @@ describe Ballast::Configuration do
45
45
  before(:example) do
46
46
  expect(YAML).to receive(:load_file).with("ROOT/config/section_a.yml").and_return({"ENV" => {a: {b: 1}}, "OTHER" => {aa: 3}})
47
47
  expect(YAML).to receive(:load_file).with("ROOT/config/section-b.yml").and_return({"ENV" => {c: {d: 2}}, "OTHER" => {cc: 4}})
48
+ expect(YAML).to receive(:load_file).with("ROOT/config/section-c.yml").at_most(1).and_call_original
48
49
  end
49
50
 
50
51
  it "should load a list of sections" do
51
- Ballast::Configuration.new("section_a", "section-b", root: "ROOT", environment: "ENV")
52
+ Ballast::Configuration.new("section_a", "section-b", "section-c", root: "ROOT", environment: "ENV")
52
53
  end
53
54
 
54
- it "should only load specific environment" do
55
- subject = Ballast::Configuration.new("section_a", "section-b", root: "ROOT", environment: "ENV")
55
+ it "should only load specific environment and fallback for missing files" do
56
+ subject = Ballast::Configuration.new("section_a", "section-b", "section-c", root: "ROOT", environment: "ENV")
56
57
  expect(subject["section_a"].keys).to eq(["a"])
57
58
  expect(subject["section_b"].keys).to eq(["c"])
59
+ expect(subject["section_c"].keys).to eq([])
58
60
  end
59
61
  end
60
62
 
@@ -134,11 +134,23 @@ describe Ballast::Service do
134
134
  it "should raise a failure" do
135
135
  expect { DummyService.new.fail!("DETAILS") }.to raise_error(Ballast::Errors::Failure)
136
136
  end
137
+
138
+ it "should accept status and error keywords" do
139
+ expect { DummyService.new.fail!(status: "STATUS", error: "ERROR") }.to raise_error(Ballast::Errors::Failure) do |error|
140
+ expect(error.details).to eq({status: "STATUS", error: "ERROR"})
141
+ end
142
+ end
137
143
  end
138
144
 
139
145
  describe "#fail_validation!" do
140
146
  it "should raise a validation failure" do
141
147
  expect { DummyService.new.fail_validation!("DETAILS") }.to raise_error(Ballast::Errors::ValidationFailure)
142
148
  end
149
+
150
+ it "should accept status and error keywords" do
151
+ expect { DummyService.new.fail_validation!(status: "STATUS", error: "ERROR") }.to raise_error(Ballast::Errors::ValidationFailure) do |error|
152
+ expect(error.details).to eq({status: "STATUS", error: "ERROR"})
153
+ end
154
+ end
143
155
  end
144
156
  end
@@ -4,4 +4,21 @@
4
4
  #
5
5
 
6
6
  require "bundler/setup"
7
- require File.dirname(__FILE__) + "/../lib/ballast"
7
+
8
+ if ENV["COVERAGE"]
9
+ require "simplecov"
10
+ require "coveralls"
11
+
12
+ Coveralls.wear! if ENV["CI"]
13
+
14
+ SimpleCov.start do
15
+ root = Pathname.new(File.dirname(__FILE__)) + ".."
16
+
17
+ add_filter do |src_file|
18
+ path = Pathname.new(src_file.filename).relative_path_from(root).to_s
19
+ path !~ /^lib/
20
+ end
21
+ end
22
+ end
23
+
24
+ require File.dirname(__FILE__) + "/../lib/ballast"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ballast
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.3
4
+ version: 2.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shogun
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-09 00:00:00.000000000 Z
11
+ date: 2016-03-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack
@@ -159,7 +159,6 @@ files:
159
159
  - spec/ballast/request_domain_matcher_spec.rb
160
160
  - spec/ballast/service_spec.rb
161
161
  - spec/ballast_spec.rb
162
- - spec/coverage_helper.rb
163
162
  - spec/spec_helper.rb
164
163
  homepage: http://sw.cowtech.it/ballast
165
164
  licenses:
@@ -173,7 +172,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
173
172
  requirements:
174
173
  - - ">="
175
174
  - !ruby/object:Gem::Version
176
- version: 2.1.0
175
+ version: 2.3.0
177
176
  required_rubygems_version: !ruby/object:Gem::Requirement
178
177
  requirements:
179
178
  - - ">="
@@ -198,6 +197,5 @@ test_files:
198
197
  - spec/ballast/request_domain_matcher_spec.rb
199
198
  - spec/ballast/service_spec.rb
200
199
  - spec/ballast_spec.rb
201
- - spec/coverage_helper.rb
202
200
  - spec/spec_helper.rb
203
201
  has_rdoc:
@@ -1,19 +0,0 @@
1
- #
2
- # This file is part of the ballast gem. Copyright (C) 2013 and above Shogun <shogun@cowtech.it>.
3
- # Licensed under the MIT license, which can be found at http://www.opensource.org/licenses/mit-license.php.
4
- #
5
-
6
- require "pathname"
7
- require "simplecov"
8
- require "coveralls"
9
-
10
- Coveralls.wear! if ENV["CI"] || ENV["JENKINS_URL"] # Do not load outside Travis
11
-
12
- SimpleCov.start do
13
- root = Pathname.new(File.dirname(__FILE__)) + ".."
14
-
15
- add_filter do |src_file|
16
- path = Pathname.new(src_file.filename).relative_path_from(root).to_s
17
- path !~ /^lib/
18
- end
19
- end