cassette 1.0.2 → 1.0.17

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.
Files changed (35) hide show
  1. checksums.yaml +5 -13
  2. data/README.md +125 -106
  3. data/lib/cassette/authentication/authorities.rb +5 -5
  4. data/lib/cassette/authentication/cache.rb +5 -6
  5. data/lib/cassette/authentication/filter.rb +9 -9
  6. data/lib/cassette/authentication/user.rb +4 -4
  7. data/lib/cassette/authentication.rb +9 -9
  8. data/lib/cassette/cache.rb +2 -4
  9. data/lib/cassette/client/cache.rb +12 -12
  10. data/lib/cassette/client.rb +11 -16
  11. data/lib/cassette/errors/not_a_customer.rb +1 -2
  12. data/lib/cassette/errors/not_an_employee.rb +1 -2
  13. data/lib/cassette/errors.rb +8 -8
  14. data/lib/cassette/rubycas/helper.rb +21 -25
  15. data/lib/cassette/rubycas/not_single_sign_out_constraint.rb +1 -2
  16. data/lib/cassette/rubycas/single_sign_out_constraint.rb +6 -7
  17. data/lib/cassette/rubycas.rb +3 -4
  18. data/lib/cassette/version.rb +6 -10
  19. data/lib/cassette.rb +21 -21
  20. data/spec/cas_spec.rb +21 -21
  21. data/spec/cassette/authentication/authorities_spec.rb +82 -0
  22. data/spec/{cas → cassette}/authentication/cache_spec.rb +0 -0
  23. data/spec/{cas → cassette}/authentication/filter_spec.rb +52 -53
  24. data/spec/cassette/authentication/user_spec.rb +70 -0
  25. data/spec/cassette/authentication_spec.rb +84 -0
  26. data/spec/{cas → cassette}/cache_spec.rb +7 -8
  27. data/spec/{cas → cassette}/client/cache_spec.rb +0 -0
  28. data/spec/{cas → cassette}/errors_spec.rb +6 -6
  29. data/spec/config.yml +4 -4
  30. data/spec/integration/cas/client_spec.rb +32 -31
  31. data/spec/spec_helper.rb +7 -7
  32. metadata +57 -57
  33. data/spec/cas/authentication/authorities_spec.rb +0 -82
  34. data/spec/cas/authentication/user_spec.rb +0 -70
  35. data/spec/cas/authentication_spec.rb +0 -84
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- NzhkMGM0Mzc3OTk4ODhjMTc5N2JiNzU4NWY5NzI0NGUyYzEzZTZiMA==
5
- data.tar.gz: !binary |-
6
- NDE0YzllMWRjN2E0M2RlNGJiN2JjY2MzYTdkZGRmNGMwOTYyZDljNQ==
2
+ SHA1:
3
+ metadata.gz: 544f24bd7aba263a362e116e0b478bc0096ca5ef
4
+ data.tar.gz: c07059b72cc076c904880bcbb2e22a6eb8347952
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- NThmZDg2MmI5OTQ1OTUwYTliYmRmZjlkZGFlMjM1MGU5ODIwNzQ1NjFmOTk2
10
- OTQyNDdhN2I4MjE0ODE0ZTZjZmUyNjQ1NzgzMDM1NjJiOGUzYTQ3MDZmZDBm
11
- Y2QyZDRjMWQ3MTZkNjBkMGIxMzExMmZjOThlNzk5OGU1OGI4Mzk=
12
- data.tar.gz: !binary |-
13
- M2QxMzhjOTJlNzUwNDk1NDE0ZWM1YjBjNDY0MTI2MmVhYTY3NTkzMjcwYjM4
14
- YTYwZmM0NTQ5NzcxYzc3NGIwYWMyZjRhYjY1NTQwMzhlMmU1Nzg0N2JmNGJk
15
- MjU4MjZlNDBjZTBmNWVmODI1MDIwZmQzZmU0MGU3YmE2YTRiZWQ=
6
+ metadata.gz: 7af98b5bc6c3070704b139b0cab9cbc8da25d646955036adc2335ea225ea241708ef7aa998440d233d0b4bd58ba4c5e5df9c2a5c788e17d9c55f700577feef31
7
+ data.tar.gz: fe36aae7cdbb1ddaf2ed77504181eb53885ab7aed58467cee87ca474932ea0541e0c7b96feb7839e4884d81f58140d6e5a84635f5267b0a4e71b0d12caf1ff93
data/README.md CHANGED
@@ -1,106 +1,125 @@
1
- # Cassette::Client
2
-
3
- Library to generate and validate STs and TGTs
4
-
5
- ## Installation
6
-
7
- Add this line to your application's Gemfile:
8
-
9
- gem 'cassette'
10
-
11
- And then execute:
12
-
13
- $ bundle
14
-
15
- ## Usage
16
-
17
- Require this library and create an intializer to set its configuration:
18
-
19
-
20
- Cassette.config = config
21
-
22
-
23
- where config is an object that responds to the methods #base for the base CAS uri, #username and #password
24
- if you are authenticating on other systems and #service and #base\_authority if you are using the authentication filter
25
- to authenticate your app
26
-
27
-
28
- You may also set the caching backend using the .backend= module method:
29
-
30
-
31
- Cassette::Cache.backend = ActiveSupport::Cache::MemcacheStorage.new
32
-
33
-
34
- By default, Cassette::Cache will check if you have Rails.cache defined or instantiate a new ActiveSupport::Cache::MemoryStore
35
-
36
-
37
- To authenticate your Rails app, add to your ApplicationController (or any authenticated controller):
38
-
39
-
40
- class ApplicationController < ActionController::Base
41
- include Cassette::Authentication::Filter
42
-
43
-
44
- (...)
45
-
46
- end
47
-
48
-
49
- You should also rescue from Cassette::Errors::Forbidden with more friendly errors
50
-
51
- If you wish to have actions that skip the authentication filter, add to your controller:
52
-
53
-
54
- skip_authentication [options]
55
-
56
-
57
- Where options are the same options you can pass to Rails' __skip_before_filter__ method
58
-
59
- ## RubyCAS client helpers
60
-
61
-
62
- If you are authenticating users with RubyCAS and want role checking, in your rubycas initializer:
63
-
64
-
65
- require "cas/rubycas"
66
-
67
-
68
- And in your ApplicationController (or any authenticated controller):
69
-
70
-
71
- include Cassette::Rubycas::Helper
72
-
73
- # - Allow only employees:
74
- #
75
- # before_filter :employee_only_filter
76
- #
77
- # rescue_from Cassette::Errors::NotAnEmployee d
78
- # redirect_to '/403.html'
79
- # end
80
-
81
- # - Allow only customers:
82
- #
83
- # before_filter :customer_only_filter
84
- #
85
- # rescue_from Cassette::Errors::NotACustomer do
86
- # redirect_to '/403.html'
87
- # end
88
-
89
-
90
- ## Instantiating Cassette::Client and Cassette::Authentication
91
-
92
- You can create your own instances of __Cassette::Client__ (st/tgt generator) and __Cassette::Authentication__ (st validator).
93
-
94
- The constructor accepts a hash with keys (as symbols) for the values of cache, logger, http_client and configuration.
95
-
96
- All values default to the same values used when accessing the class methods directly.
97
-
98
- Please check the constructors or integration specs for details.
99
-
100
- ## Contributing
101
-
102
- 1. Fork it
103
- 2. Create your feature branch (`git checkout -b my-new-feature`)
104
- 3. Commit your changes (`git commit -am 'Added some feature'`)
105
- 4. Push to the branch (`git push origin my-new-feature`)
106
- 5. Create new Pull Request
1
+ # Cassette::Client
2
+
3
+ Library to generate and validate STs and TGTs
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'cassette'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ ```shell
16
+ $ bundle
17
+ ```
18
+
19
+ ## Usage
20
+
21
+ Require this library and create an intializer to set its configuration:
22
+
23
+ ```ruby
24
+ Cassette.config = config
25
+ ```
26
+
27
+ where config is an object that responds to the methods #base for the base CAS uri, #username and #password
28
+ if you are authenticating on other systems and #service and #base\_authority if you are using the authentication filter
29
+ to authenticate your app
30
+
31
+
32
+ You may also set the caching backend using the .backend= module method:
33
+
34
+ ```ruby
35
+ Cassette::Cache.backend = ActiveSupport::Cache::MemcacheStorage.new
36
+ ```
37
+
38
+ By default, Cassette::Cache will check if you have Rails.cache defined or instantiate a new ActiveSupport::Cache::MemoryStore
39
+
40
+
41
+ To authenticate your Rails app, add to your ApplicationController (or any authenticated controller):
42
+
43
+ ```ruby
44
+ class ApplicationController < ActionController::Base
45
+ include Cassette::Authentication::Filter
46
+
47
+ # ...
48
+ end
49
+ ```
50
+
51
+ You should also rescue from Cassette::Errors::Forbidden with more friendly errors
52
+
53
+ If you wish to have actions that skip the authentication filter, add to your controller:
54
+
55
+ ```ruby
56
+ class SomeController < ApplicationController
57
+ skip_authentication # [*options]
58
+
59
+ # skip_authentication only: "index"
60
+ end
61
+ ```
62
+
63
+ Where options are the same options you can pass to Rails' __skip_before_filter__ method
64
+
65
+ ## RubyCAS client helpers
66
+
67
+
68
+ If you are authenticating users with RubyCAS and want role checking, in your rubycas initializer:
69
+
70
+ ```ruby
71
+ require "cas/rubycas"
72
+ ```
73
+
74
+ And in your ApplicationController (or any authenticated controller):
75
+
76
+ ```ruby
77
+ class SomeController < ApplicationController
78
+ include Cassette::Rubycas::Helper
79
+
80
+ # - Allow only employees:
81
+ #
82
+ # before_filter :employee_only_filter
83
+ #
84
+ # rescue_from Cassette::Errors::NotAnEmployee do
85
+ # redirect_to '/403.html'
86
+ # end
87
+
88
+ # - Allow only customers:
89
+ #
90
+ # before_filter :customer_only_filter
91
+ #
92
+ # rescue_from Cassette::Errors::NotACustomer do
93
+ # redirect_to '/403.html'
94
+ # end
95
+ end
96
+ ```
97
+
98
+ ## Instantiating Cassette::Client and Cassette::Authentication
99
+
100
+ You can create your own instances of __Cassette::Client__ (st/tgt generator) and __Cassette::Authentication__ (st validator).
101
+
102
+ The constructor accepts a hash with keys (as symbols) for the values of cache, logger, http_client and configuration.
103
+
104
+ All values default to the same values used when accessing the class methods directly.
105
+
106
+ Please check the constructors or integration specs for details.
107
+
108
+ ## About caching and tests
109
+
110
+ It is a good idea to always clear the cache between tests, specially if you're
111
+ using VCR. You can do it by using the invoking the `#clear` method of the cache
112
+ backend in use. The following excerpt will clear the cache of the default client
113
+ `Cassette::Client` instance:
114
+
115
+ ```
116
+ Cassette::Client.cache.backend.clear
117
+ ```
118
+
119
+ ## Contributing
120
+
121
+ 1. Fork it
122
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
123
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
124
+ 4. Push to the branch (`git push origin my-new-feature`)
125
+ 5. Create new Pull Request
@@ -1,6 +1,6 @@
1
1
  # encoding: UTF-8
2
2
 
3
- require "cassette/authentication"
3
+ require 'cassette/authentication'
4
4
 
5
5
  class Cassette::Authentication::Authorities
6
6
  def self.parse(authorities, base_authority = nil)
@@ -12,20 +12,20 @@ class Cassette::Authentication::Authorities
12
12
  end
13
13
 
14
14
  def has_raw_role?(role)
15
- return true if ENV["NOAUTH"]
15
+ return true if ENV['NOAUTH']
16
16
  @authorities.include?(role)
17
17
  end
18
18
 
19
19
  def has_role?(role)
20
- return true if ENV["NOAUTH"]
21
- has_raw_role?("#{base}_#{role.to_s.upcase.gsub("_", "-")}")
20
+ return true if ENV['NOAUTH']
21
+ has_raw_role?("#{base}_#{role.to_s.upcase.gsub('_', '-')}")
22
22
  end
23
23
 
24
24
  def initialize(authorities, base_authority = nil)
25
25
  @base_authority = base_authority || Cassette.config.base_authority
26
26
 
27
27
  if authorities.is_a?(String)
28
- @authorities = authorities.gsub(/^\[(.*)\]$/, "\\1").split(",").map(&:strip)
28
+ @authorities = authorities.gsub(/^\[(.*)\]$/, '\\1').split(',').map(&:strip)
29
29
  else
30
30
  @authorities = Array(authorities).map(&:strip)
31
31
  end
@@ -1,7 +1,7 @@
1
1
  # encoding: UTF-8
2
2
 
3
- require "cassette/authentication"
4
- require "cassette/cache"
3
+ require 'cassette/authentication'
4
+ require 'cassette/cache'
5
5
 
6
6
  class Cassette::Authentication::Cache
7
7
  include Cassette::Cache
@@ -11,7 +11,7 @@ class Cassette::Authentication::Cache
11
11
  end
12
12
 
13
13
  def fetch_authentication(ticket, options = {}, &block)
14
- options = {expires_in: 5 * 60, max_uses: 5000, force: false}.merge(options)
14
+ options = { expires_in: 5 * 60, max_uses: 5000, force: false }.merge(options)
15
15
  fetch("Cassette::Authentication.validate_ticket(#{ticket})", options) do
16
16
  logger.info("Authentication for #{ticket} is not cached")
17
17
  block.call
@@ -19,12 +19,11 @@ class Cassette::Authentication::Cache
19
19
  end
20
20
 
21
21
  def clear_authentication_cache!
22
- backend.delete_matched("Cassette::Authentication.validate_ticket*")
23
- backend.delete_matched("#{uses_key("Cassette::Authentication.validate_ticket")}*")
22
+ backend.delete_matched('Cassette::Authentication.validate_ticket*')
23
+ backend.delete_matched("#{uses_key('Cassette::Authentication.validate_ticket')}*")
24
24
  end
25
25
 
26
26
  protected
27
27
 
28
28
  attr_accessor :logger
29
29
  end
30
-
@@ -1,7 +1,7 @@
1
1
  # encoding: UTF-8
2
2
 
3
- require "active_support/concern"
4
- require "cassette/authentication/user"
3
+ require 'active_support/concern'
4
+ require 'cassette/authentication/user'
5
5
 
6
6
  module Cassette::Authentication::Filter
7
7
  extend ActiveSupport::Concern
@@ -18,10 +18,10 @@ module Cassette::Authentication::Filter
18
18
  end
19
19
 
20
20
  def validate_authentication_ticket(service = Cassette.config.service)
21
- ticket = request.headers["Service-Ticket"] || params[:ticket]
21
+ ticket = request.headers['Service-Ticket'] || params[:ticket]
22
22
 
23
- if ENV["NOAUTH"] && !ticket
24
- Cassette.logger.debug "NOAUTH set and no Service Ticket, skipping authentication"
23
+ if ENV['NOAUTH']
24
+ Cassette.logger.debug 'NOAUTH set and no Service Ticket, skipping authentication'
25
25
  self.current_user = Cassette::Authentication::User.new
26
26
  return
27
27
  end
@@ -30,12 +30,12 @@ module Cassette::Authentication::Filter
30
30
  end
31
31
 
32
32
  def validate_role!(role)
33
- return if ENV["NOAUTH"]
34
- raise Cassette::Errors::Forbidden unless current_user.has_role?(role)
33
+ return if ENV['NOAUTH']
34
+ fail Cassette::Errors::Forbidden unless current_user.has_role?(role)
35
35
  end
36
36
 
37
37
  def validate_raw_role!(role)
38
- return if ENV["NOAUTH"]
39
- raise Cassette::Errors::Forbidden unless current_user.has_raw_role?(role)
38
+ return if ENV['NOAUTH']
39
+ fail Cassette::Errors::Forbidden unless current_user.has_raw_role?(role)
40
40
  end
41
41
  end
@@ -1,8 +1,8 @@
1
1
  # encoding: UTF-8
2
2
 
3
- require "cassette/authentication"
4
- require "cassette/authentication/authorities"
5
- require "delegate"
3
+ require 'cassette/authentication'
4
+ require 'cassette/authentication/authorities'
5
+ require 'delegate'
6
6
 
7
7
  class Cassette::Authentication::User
8
8
  attr_accessor :login, :name, :authorities, :email, :ticket
@@ -16,7 +16,7 @@ class Cassette::Authentication::User
16
16
  @email = attrs[:email]
17
17
  @ticket = attrs[:ticket]
18
18
  @authorities = Cassette::Authentication::Authorities
19
- .parse(attrs.fetch(:authorities, "[]"), config && config.base_authority)
19
+ .parse(attrs.fetch(:authorities, '[]'), config && config.base_authority)
20
20
  end
21
21
 
22
22
  %w(customer employee).each do |type|
@@ -1,6 +1,6 @@
1
1
  # encoding: UTF-8
2
2
 
3
- require "active_support/xml_mini"
3
+ require 'active_support/xml_mini'
4
4
  ActiveSupport::XmlMini.backend = 'LibXML'
5
5
 
6
6
  module Cassette
@@ -19,12 +19,12 @@ module Cassette
19
19
 
20
20
  def validate_ticket(ticket, service = config.service)
21
21
  logger.debug "Cassette::Authentication validating ticket: #{ticket}"
22
- raise Cassette::Errors::AuthorizationRequired if ticket.nil? || ticket.blank?
22
+ fail Cassette::Errors::AuthorizationRequired if ticket.nil? || ticket.blank?
23
23
 
24
24
  user = ticket_user(ticket, service)
25
25
  logger.info "Cassette::Authentication user: #{user.inspect}"
26
26
 
27
- raise Cassette::Errors::Forbidden unless user
27
+ fail Cassette::Errors::Forbidden unless user
28
28
 
29
29
  user
30
30
  end
@@ -39,15 +39,15 @@ module Cassette
39
39
 
40
40
  user = nil
41
41
 
42
- ActiveSupport::XmlMini.with_backend("LibXML") do
42
+ ActiveSupport::XmlMini.with_backend('LibXML') do
43
43
  result = ActiveSupport::XmlMini.parse(response)
44
44
 
45
- login = result.try(:[], "serviceResponse").try(:[], "authenticationSuccess").try(:[], "user").try(:[], "__content__")
45
+ login = result.try(:[], 'serviceResponse').try(:[], 'authenticationSuccess').try(:[], 'user').try(:[], '__content__')
46
46
 
47
47
  if login
48
- attributes = result["serviceResponse"]["authenticationSuccess"]["attributes"]
49
- name = attributes.try(:[], "cn").try(:[], "__content__")
50
- authorities = attributes.try(:[], "authorities").try(:[], "__content__")
48
+ attributes = result['serviceResponse']['authenticationSuccess']['attributes']
49
+ name = attributes.try(:[], 'cn').try(:[], '__content__')
50
+ authorities = attributes.try(:[], 'authorities').try(:[], '__content__')
51
51
 
52
52
  user = Cassette::Authentication::User.new(login: login, name: name, authorities: authorities, ticket: ticket, config: config)
53
53
  end
@@ -66,7 +66,7 @@ module Cassette
66
66
  attr_accessor :cache, :logger, :http, :config
67
67
 
68
68
  def validate_uri
69
- "#{config.base.gsub(/\/?$/, "")}/serviceValidate"
69
+ "#{config.base.gsub(/\/?$/, '')}/serviceValidate"
70
70
  end
71
71
  end
72
72
  end
@@ -1,6 +1,6 @@
1
1
  # encoding: UTF-8
2
2
 
3
- require "active_support/cache"
3
+ require 'active_support/cache'
4
4
 
5
5
  module Cassette
6
6
  module Cache
@@ -14,9 +14,7 @@ module Cassette
14
14
  end
15
15
  end
16
16
 
17
- def backend=(backend)
18
- @backend = backend
19
- end
17
+ attr_writer :backend
20
18
 
21
19
  def uses_key(key)
22
20
  "uses:#{key}"
@@ -1,7 +1,7 @@
1
1
  # encoding: UTF-8
2
2
 
3
- require "cassette/client"
4
- require "cassette/cache"
3
+ require 'cassette/client'
4
+ require 'cassette/cache'
5
5
 
6
6
  class Cassette::Client::Cache
7
7
  include Cassette::Cache
@@ -10,17 +10,17 @@ class Cassette::Client::Cache
10
10
  self.logger = logger
11
11
  end
12
12
 
13
- def fetch_tgt(options = {}, &block)
14
- options = {expires_in: 4 * 3600, max_uses: 5000, force: false}.merge(options)
15
- fetch("Cassette::Client.tgt", options) do
13
+ def fetch_tgt(options = {}, &_block)
14
+ options = { expires_in: 4 * 3600, max_uses: 5000, force: false }.merge(options)
15
+ fetch('Cassette::Client.tgt', options) do
16
16
  self.clear_st_cache!
17
- logger.info "TGT is not cached"
17
+ logger.info 'TGT is not cached'
18
18
  yield
19
19
  end
20
20
  end
21
21
 
22
- def fetch_st(service, options = {}, &block)
23
- options = {max_uses: 2000, expires_in: 252, force: false}.merge(options)
22
+ def fetch_st(service, options = {}, &_block)
23
+ options = { max_uses: 2000, expires_in: 252, force: false }.merge(options)
24
24
  fetch("Cassette::Client.st(#{service})", options) do
25
25
  logger.info "ST for #{service} is not cached"
26
26
  yield
@@ -28,13 +28,13 @@ class Cassette::Client::Cache
28
28
  end
29
29
 
30
30
  def clear_tgt_cache!
31
- backend.delete("Cassette::Client.tgt")
32
- backend.delete("#{uses_key("Cassette::Client.tgt")}")
31
+ backend.delete('Cassette::Client.tgt')
32
+ backend.delete("#{uses_key('Cassette::Client.tgt')}")
33
33
  end
34
34
 
35
35
  def clear_st_cache!
36
- backend.delete_matched("Cassette::Client.st*")
37
- backend.delete_matched("#{uses_key("Cassette::Client.st")}*")
36
+ backend.delete_matched('Cassette::Client.st*')
37
+ backend.delete_matched("#{uses_key('Cassette::Client.st')}*")
38
38
  end
39
39
 
40
40
  protected
@@ -15,14 +15,14 @@ module Cassette
15
15
  end
16
16
 
17
17
  def health_check
18
- st_for("monitoring")
18
+ st_for('monitoring')
19
19
  end
20
20
 
21
21
  def tgt(usr, pwd, force = false)
22
- logger.info "Requesting TGT"
22
+ logger.info 'Requesting TGT'
23
23
  cache.fetch_tgt(force: force) do
24
24
  response = http.post(tickets_uri, username: usr, password: pwd)
25
- tgt = $1 if response.headers["Location"] =~ /tickets\/(.*)/
25
+ tgt = Regexp.last_match(1) if response.headers['Location'] =~ /tickets\/(.*)/
26
26
  logger.info "TGT is #{tgt}"
27
27
  tgt
28
28
  end
@@ -46,23 +46,18 @@ module Cassette
46
46
 
47
47
  attr_accessor :cache, :logger, :http, :config
48
48
 
49
- def st_with_retry(user, pass, service)
49
+ def st_with_retry(user, pass, service, retrying = true)
50
+ st(tgt(user, pass, retrying), service)
51
+ rescue Cassette::Errors::NotFound => e
52
+ raise e unless retrying
53
+
54
+ logger.info 'Got 404 response, regenerating TGT'
50
55
  retrying = false
51
- begin
52
- st(tgt(user, pass, retrying), service)
53
- rescue Cassette::Errors::NotFound => e
54
- unless retrying
55
- logger.info "Got 404 response, regenerating TGT"
56
- retrying = true
57
- retry
58
- end
59
- raise e
60
- end
56
+ retry
61
57
  end
62
58
 
63
59
  def tickets_uri
64
- "#{config.base.gsub(/\/?$/, "")}/v1/tickets"
60
+ "#{config.base.gsub(/\/?$/, '')}/v1/tickets"
65
61
  end
66
62
  end
67
63
  end
68
-
@@ -1,6 +1,6 @@
1
1
  # encoding: utf-8
2
2
 
3
- require "cassette/errors"
3
+ require 'cassette/errors'
4
4
 
5
5
  module Cassette
6
6
  module Errors
@@ -11,4 +11,3 @@ module Cassette
11
11
  end
12
12
  end
13
13
  end
14
-
@@ -1,6 +1,6 @@
1
1
  # encoding: utf-8
2
2
 
3
- require "cassette/errors"
3
+ require 'cassette/errors'
4
4
 
5
5
  module Cassette
6
6
  module Errors
@@ -11,4 +11,3 @@ module Cassette
11
11
  end
12
12
  end
13
13
  end
14
-
@@ -1,6 +1,6 @@
1
1
  # encoding: UTF-8
2
2
 
3
- require "active_support/inflector"
3
+ require 'active_support/inflector'
4
4
 
5
5
  module Cassette
6
6
  module Errors
@@ -10,16 +10,16 @@ module Cassette
10
10
  403 => :forbidden,
11
11
  500 => :internal_server_error,
12
12
  404 => :not_found,
13
- 412 => :precondition_failed,
13
+ 412 => :precondition_failed
14
14
  }
15
15
 
16
16
  def self.raise_by_code(code)
17
17
  name = TYPES[code.to_i]
18
18
 
19
19
  if name
20
- raise error_class(name)
20
+ fail error_class(name)
21
21
  else
22
- raise error_class(:internal_server_error)
22
+ fail error_class(:internal_server_error)
23
23
  end
24
24
  end
25
25
 
@@ -29,16 +29,16 @@ module Cassette
29
29
 
30
30
  class Base < StandardError
31
31
  def code
32
- self.class.const_get("CODE")
32
+ self.class.const_get('CODE')
33
33
  end
34
34
  end
35
35
 
36
36
  TYPES.each do |status, name|
37
37
  const_set(name.to_s.camelize, Class.new(Errors::Base))
38
- error_class(name).const_set("CODE", status)
38
+ error_class(name).const_set('CODE', status)
39
39
  end
40
40
  end
41
41
  end
42
42
 
43
- require "cassette/errors/not_an_employee"
44
- require "cassette/errors/not_a_customer"
43
+ require 'cassette/errors/not_an_employee'
44
+ require 'cassette/errors/not_a_customer'