saddle 0.0.31 → 0.0.32

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -12,3 +12,7 @@ group :test do
12
12
  gem 'airbrake'
13
13
  gem 'statsd-ruby', :require => ['statsd']
14
14
  end
15
+
16
+ group :development, :test do
17
+ gem 'pry'
18
+ end
data/Gemfile.lock CHANGED
@@ -9,6 +9,7 @@ GEM
9
9
  builder
10
10
  json
11
11
  builder (3.2.0)
12
+ coderay (1.0.9)
12
13
  diff-lcs (1.2.4)
13
14
  faraday (0.8.7)
14
15
  multipart-post (~> 1.1)
@@ -16,8 +17,13 @@ GEM
16
17
  faraday (>= 0.7.4, < 0.9)
17
18
  i18n (0.6.1)
18
19
  json (1.7.7)
20
+ method_source (0.8.1)
19
21
  multi_json (1.7.3)
20
22
  multipart-post (1.2.0)
23
+ pry (0.9.12.2)
24
+ coderay (~> 1.0.5)
25
+ method_source (~> 0.8)
26
+ slop (~> 3.4)
21
27
  rspec (2.13.0)
22
28
  rspec-core (~> 2.13.0)
23
29
  rspec-expectations (~> 2.13.0)
@@ -27,6 +33,7 @@ GEM
27
33
  diff-lcs (>= 1.1.3, < 2.0)
28
34
  rspec-instafail (0.2.4)
29
35
  rspec-mocks (2.13.1)
36
+ slop (3.4.5)
30
37
  statsd-ruby (1.2.0)
31
38
 
32
39
  PLATFORMS
@@ -37,6 +44,7 @@ DEPENDENCIES
37
44
  airbrake
38
45
  faraday (~> 0.8.7)
39
46
  faraday_middleware (~> 0.9.0)
47
+ pry
40
48
  rspec (~> 2.13.0)
41
49
  rspec-instafail (~> 0.2)
42
50
  statsd-ruby
@@ -1,4 +1,4 @@
1
- require 'active_support'
1
+ require 'active_support/core_ext/string'
2
2
 
3
3
 
4
4
 
@@ -66,11 +66,7 @@ module Saddle
66
66
  # Create the new endpoint
67
67
  endpoint_instance = endpoint_class.new(@requester, method_name, self)
68
68
  # Attach the endpoint as an instance variable and method
69
- method_name ||= ActiveSupport::Inflector.underscore(
70
- ActiveSupport::Inflector.demodulize(
71
- endpoint_class.name
72
- )
73
- )
69
+ method_name ||= endpoint_class.name.demodulize.underscore
74
70
  self.instance_variable_set("@#{method_name}", endpoint_instance)
75
71
  self.class.class_eval { define_method(method_name) { endpoint_instance } }
76
72
  endpoint_instance
@@ -115,11 +111,7 @@ module Saddle
115
111
  if _is_root?
116
112
  nil
117
113
  else
118
- ActiveSupport::Inflector.underscore(
119
- ActiveSupport::Inflector.demodulize(
120
- self.class.name
121
- )
122
- )
114
+ self.class.name.demodulize.underscore
123
115
  end
124
116
  end
125
117
  end
@@ -1,4 +1,4 @@
1
- require 'active_support'
1
+ require 'active_support/core_ext/string'
2
2
 
3
3
  require 'saddle/endpoint'
4
4
 
@@ -16,9 +16,12 @@ module Saddle
16
16
  # Build out the endpoint structure from the root of the implementation
17
17
  def build_tree(requester)
18
18
  root_node = build_root_node(requester)
19
- # If we have an 'endpoints' directory, build it out
20
- if knows_root? && Dir.exists?(endpoints_directory)
21
- Dir["#{endpoints_directory}/**/*.rb"].each { |f| load(f) }
19
+ # Search out the implementations directory structure for endpoints
20
+ if defined?(self.implementation_root)
21
+ # For each endpoints directory, recurse down it to load the modules
22
+ endpoints_directories.each do |endpoints_directories|
23
+ Dir["#{endpoints_directories}/**/*.rb"].each { |f| require(f) }
24
+ end
22
25
  build_node_children(self.endpoints_module, root_node, requester)
23
26
  end
24
27
  root_node
@@ -28,14 +31,14 @@ module Saddle
28
31
  # Build our root node here. The root node is special in that it lives below
29
32
  # the 'endpoints' directory, and so we need to manually check if it exists.
30
33
  def build_root_node(requester)
31
- if knows_root?
34
+ if defined?(self.implementation_root)
32
35
  root_endpoint_file = File.join(
33
36
  self.implementation_root,
34
37
  'root_endpoint.rb'
35
38
  )
36
39
  if File.file?(root_endpoint_file)
37
40
  # Load it and create our base endpoint
38
- load(root_endpoint_file)
41
+ require(root_endpoint_file)
39
42
  # RootEndpoint is the special class name for a root endpoint
40
43
  root_node_class = self.implementation_module::RootEndpoint
41
44
  else
@@ -52,6 +55,7 @@ module Saddle
52
55
 
53
56
  # Build out the traversal tree by module namespace
54
57
  def build_node_children(current_module, current_node, requester)
58
+ return unless current_module
55
59
  current_module.constants.each do |const_symbol|
56
60
  const = current_module.const_get(const_symbol)
57
61
 
@@ -60,7 +64,7 @@ module Saddle
60
64
  # Build the branch out with a base endpoint
61
65
  branch_node = current_node._build_and_attach_node(
62
66
  Saddle::TraversalEndpoint,
63
- ActiveSupport::Inflector.underscore(const_symbol)
67
+ const_symbol.underscore
64
68
  )
65
69
  # Build out the branch's endpoints on the new branch node
66
70
  self.build_node_children(const, branch_node, requester)
@@ -78,27 +82,23 @@ module Saddle
78
82
  # Get the module that the client implementation belongs to. This will act
79
83
  # as the root namespace for endpoint traversal and construction
80
84
  def implementation_module
81
- ::ActiveSupport::Inflector.constantize(
82
- self.name.split('::')[0..-2].join('::')
83
- )
85
+ self.name.split('::')[0..-2].join('::').constantize
86
+ end
87
+
88
+ # Get all directories under the implementation root named 'endpoints'
89
+ # This search allows for flexible structuring of gem
90
+ def endpoints_directories
91
+ Dir["#{implementation_root}/**/"].select { |d| d.ends_with?('endpoints/') }
84
92
  end
85
93
 
86
94
  # Get the Endpoints module that lives within this implementation's
87
95
  # namespace
88
96
  def endpoints_module
89
- implementation_module.const_get('Endpoints')
90
- end
91
-
92
- # Get the path to the 'endpoints' directory, based upon the client
93
- # class that inherited Saddle
94
- def endpoints_directory
95
- File.join(self.implementation_root, 'endpoints')
96
- end
97
-
98
- # If this client was not fully constructed, it may not even have an
99
- # implementation root. Allow that behavior to avoid filesystem searching.
100
- def knows_root?
101
- defined?(self.implementation_root)
97
+ begin
98
+ implementation_module.const_get('Endpoints')
99
+ rescue NameError
100
+ nil # If there is no endpoints module, we just won't load any
101
+ end
102
102
  end
103
103
 
104
104
  end
@@ -1,3 +1,5 @@
1
+ require 'active_support/core_ext/string'
2
+
1
3
  require 'statsd'
2
4
  require 'faraday'
3
5
 
@@ -36,7 +38,7 @@ module Saddle
36
38
  elsif env[:request][:saddle]
37
39
  statsd_path_components = [
38
40
  'saddle',
39
- ActiveSupport::Inflector.underscore(env[:request][:saddle][:client].name),
41
+ env[:request][:saddle][:client].name.underscore,
40
42
  ]
41
43
  if env[:request][:saddle][:call_chain] && env[:request][:saddle][:action]
42
44
  statsd_path_components += env[:request][:saddle][:call_chain]
@@ -1,3 +1,3 @@
1
1
  module Saddle
2
- VERSION = '0.0.31'
2
+ VERSION = '0.0.32'
3
3
  end
@@ -1,12 +1,11 @@
1
- require 'saddle'
2
-
1
+ require 'spec_helper'
3
2
 
4
3
 
5
4
  describe 'FaradayMiddleware::Instrumentation' do
6
5
 
7
6
  context "test integration of instrumentation middleware" do
8
7
 
9
- it "with a request" do
8
+ it "with a request should not bomb" do
10
9
  client = Saddle::Client.create(
11
10
  :stubs => Faraday::Adapter::Test::Stubs.new do |stub|
12
11
  stub.get('/test') {
@@ -19,9 +18,6 @@ describe 'FaradayMiddleware::Instrumentation' do
19
18
  end
20
19
  )
21
20
 
22
-
23
-
24
-
25
21
  client.requester.get('/test').should == 'Party on!'
26
22
  end
27
23
 
@@ -1,6 +1,6 @@
1
- require 'saddle'
2
- require 'saddle/middleware/logging/airbrake'
1
+ require 'spec_helper'
3
2
 
3
+ require 'saddle/middleware/logging/airbrake'
4
4
 
5
5
 
6
6
  describe Saddle::Middleware::Logging::AirbrakeLogger do
@@ -1,6 +1,6 @@
1
- require 'saddle'
2
- require 'saddle/middleware/logging/rails'
1
+ require 'spec_helper'
3
2
 
3
+ require 'saddle/middleware/logging/rails'
4
4
 
5
5
 
6
6
  describe Saddle::Middleware::Logging::RailsLogger do
@@ -1,6 +1,6 @@
1
- require 'saddle'
2
- require 'saddle/middleware/logging/statsd'
1
+ require 'spec_helper'
3
2
 
3
+ require 'saddle/middleware/logging/statsd'
4
4
 
5
5
 
6
6
  describe Saddle::Middleware::Logging::StatsdLogger do
@@ -1,6 +1,4 @@
1
- require 'faraday'
2
- require 'saddle'
3
-
1
+ require 'spec_helper'
4
2
 
5
3
 
6
4
  describe Saddle::Client do
@@ -1,5 +1,4 @@
1
- require 'saddle'
2
-
1
+ require 'spec_helper'
3
2
 
4
3
 
5
4
  describe Saddle::Client do
@@ -1,9 +1,9 @@
1
- require 'faraday'
2
- require 'saddle'
1
+ require 'spec_helper'
3
2
 
4
-
5
-
6
- ### Make sure that multiple implementations of Saddle clients don't conflict with each other's middlewar.
3
+ ###
4
+ # Make sure that multiple implementations of Saddle clients don't conflict with
5
+ # each other's middleware.
6
+ ###
7
7
 
8
8
  describe Saddle::Client do
9
9
 
@@ -1,4 +1,5 @@
1
- require 'saddle'
1
+ require 'spec_helper'
2
+
2
3
 
3
4
  describe Saddle::Client do
4
5
 
@@ -1,4 +1,5 @@
1
- require 'saddle'
1
+ require 'spec_helper'
2
+
2
3
 
3
4
  describe Saddle::Client do
4
5
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: saddle
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.31
4
+ version: 0.0.32
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: