garage_client-rails 0.0.1

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 973a5ba4b99f6c2b36bc2bbcaae86e25bdacc31b
4
+ data.tar.gz: 8ccc69784d18d0a49bae36ad6ddbdbe2327639b0
5
+ SHA512:
6
+ metadata.gz: 8a66800647d504ef01773e44990fb463434dd15d5103e81f3cafff1bff4178d615a6763c7bdf927e646d330d8d141422af9cd2fd9c776f9a9cdb36afc533fbcd
7
+ data.tar.gz: bef8cb1a6487cfcb647e2b811b754cb9a1751756c22157342938b74df1eee8122c35cc236d1f70d2915d4411428d3561126fa4c351320f2b596aa2229996b043
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
4
+ - 2.3.0
5
+ before_install: gem install bundler -v 1.11.2
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/README.md ADDED
@@ -0,0 +1,33 @@
1
+ # GarageClient::Rails
2
+
3
+ garage_client-rails is a garage application api client for rails.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'garage_client-rails'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install garage_client-rails
20
+
21
+ ## Usage
22
+
23
+ You can use only to `require 'garage_clent/rails'` or `gem 'garage_client-rails'` into Gemfile
24
+
25
+ ## Development
26
+
27
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
28
+
29
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
30
+
31
+ ## Contributing
32
+
33
+ Bug reports and pull requests are welcome on GitHub at https://github.com/TakatoshiMaeda/garage_client-rails.
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new("spec")
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "garage_client/rails"
5
+
6
+ require "pry"
7
+ Pry.start
data/bin/setup ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
@@ -0,0 +1,32 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'garage_client/rails/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "garage_client-rails"
7
+ spec.version = GarageClient::Rails::VERSION
8
+ spec.authors = ["Takatoshi Maeda"]
9
+ spec.email = ["me@tmd.tw"]
10
+
11
+ spec.summary = %q{GarageClient for rails}
12
+ spec.description = %q{garage_client-rails is a garage application api client for rails}
13
+ spec.homepage = "https://github.com/TakatoshiMaeda/garage_client-rails"
14
+
15
+ if spec.respond_to?(:metadata)
16
+ spec.metadata['allowed_push_host'] = "https://rubygems.org/"
17
+ else
18
+ raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
19
+ end
20
+
21
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
22
+ spec.bindir = "exe"
23
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
+ spec.require_paths = ["lib"]
25
+
26
+ spec.add_dependency "garage_client"
27
+ spec.add_dependency "rails", '>= 4.0.0'
28
+
29
+ spec.add_development_dependency "rake"
30
+ spec.add_development_dependency "rspec"
31
+ spec.add_development_dependency "pry"
32
+ end
@@ -0,0 +1,30 @@
1
+ require 'garage_client/rails/log_subscriber'
2
+ require 'active_support/core_ext/module/attr_internal'
3
+
4
+ module GarageClient::Rails
5
+ module ControllerRuntime
6
+ extend ActiveSupport::Concern
7
+
8
+ protected
9
+
10
+ attr_internal :garage_client_runtime
11
+
12
+ def process_action(action, *args)
13
+ GarageClient::Rails::LogSubscriber.reset_runtime
14
+ super
15
+ end
16
+
17
+ def append_info_to_payload(payload)
18
+ super
19
+ payload[:garage_client_runtime] = (garage_client_runtime || 0) + GarageClient::Rails::LogSubscriber.reset_runtime
20
+ end
21
+
22
+ module ClassMethods
23
+ def log_process_action(payload)
24
+ messages, garage_client_runtime = super, payload[:garage_client_runtime]
25
+ messages << ("GarageClient: %.1fms" % garage_client_runtime.to_f) if garage_client_runtime
26
+ messages
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,43 @@
1
+ require 'active_support/log_subscriber'
2
+ require 'garage_client/rails/runtime_registry'
3
+
4
+ module GarageClient::Rails
5
+ class LogSubscriber < ActiveSupport::LogSubscriber
6
+ def self.runtime=(value)
7
+ GarageClient::Rails::RuntimeRegistry.garage_client_runtime = value
8
+ end
9
+
10
+ def self.runtime
11
+ GarageClient::Rails::RuntimeRegistry.garage_client_runtime ||= 0
12
+ end
13
+
14
+ def self.reset_runtime
15
+ rt, self.runtime = runtime, 0
16
+ rt
17
+ end
18
+
19
+ def request(event)
20
+ return if logger.nil?
21
+ return unless logger.debug?
22
+
23
+ self.class.runtime += event.duration
24
+
25
+ payload = event.payload
26
+
27
+ name = color("GarageClient (#{event.duration.round(1)}ms)", GREEN, true)
28
+ method = color(payload[:method].to_s.upcase, WHITE, true)
29
+ url = color(payload[:url], WHITE, true)
30
+ body = (payload[:body].nil? ? nil : color(payload[:body], WHITE, false))
31
+
32
+ message = ""
33
+ message << " #{name} #{method} #{url}"
34
+ unless body.blank?
35
+ message << " body=#{body}"
36
+ end
37
+
38
+ debug(message)
39
+ end
40
+ end
41
+ end
42
+
43
+ GarageClient::Rails::LogSubscriber.attach_to(:garage_client)
@@ -0,0 +1,25 @@
1
+ require "rails"
2
+
3
+ module GarageClient::Rails
4
+ class Railtie < Rails::Railtie
5
+ config.action_dispatch.rescue_responses.merge!(
6
+ 'GarageClient::BadRequest' => :bad_request,
7
+ 'GarageClient::Unauthorized' => :unauthorized,
8
+ 'GarageClient::Forbidden' => :forbidden,
9
+ 'GarageClient::NotFound' => :notfound,
10
+ 'GarageClient::NotAcceptable' => :not_acceptable,
11
+ 'GarageClient::Conflict' => :conflict,
12
+ 'GarageClient::UnsupportedMediaType' => :unsupported_media_type,
13
+ 'GarageClient::UnprocessableEntity' => :unprocessable_entity,
14
+ 'GarageClient::InternalServerError' => :internal_server_error,
15
+ 'GarageClient::ServiceUnavailable' => :service_unavailable,
16
+ )
17
+
18
+ initializer "garage_client.log_runtime" do
19
+ require "garage_client/rails/controller_runtime"
20
+ ActiveSupport.on_load(:action_controller) do
21
+ include GarageClient::Rails::ControllerRuntime
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,9 @@
1
+ require 'active_support/per_thread_registry'
2
+
3
+ module GarageClient::Rails
4
+ class RuntimeRegistry
5
+ extend ActiveSupport::PerThreadRegistry
6
+
7
+ attr_accessor :garage_client_runtime
8
+ end
9
+ end
@@ -0,0 +1,5 @@
1
+ module GarageClient
2
+ module Rails
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,10 @@
1
+ require 'garage_client'
2
+
3
+ module GarageClient
4
+ require 'garage_client/request_instrumentable'
5
+
6
+ module Rails
7
+ require 'garage_client/rails/version'
8
+ require 'garage_client/rails/railtie'
9
+ end
10
+ end
@@ -0,0 +1,20 @@
1
+ module GarageClient
2
+ module RequestInstrumentable
3
+ private
4
+
5
+ def request(method, path, params = {}, body = nil, options = {})
6
+ instrument(method, path, params, body) { super }
7
+ end
8
+
9
+ def instrument(method, path, params, body)
10
+ ActiveSupport::Notifications.instrumenter.instrument(
11
+ 'request.garage_client',
12
+ method: method,
13
+ url: conn.build_url(path, params).to_s,
14
+ body: body,
15
+ ) { yield }
16
+ end
17
+ end
18
+ end
19
+
20
+ GarageClient::Client.prepend(GarageClient::RequestInstrumentable)
metadata ADDED
@@ -0,0 +1,129 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: garage_client-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Takatoshi Maeda
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-04-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: garage_client
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rails
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 4.0.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 4.0.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
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'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: garage_client-rails is a garage application api client for rails
84
+ email:
85
+ - me@tmd.tw
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".travis.yml"
92
+ - Gemfile
93
+ - README.md
94
+ - Rakefile
95
+ - bin/console
96
+ - bin/setup
97
+ - garage_client-rails.gemspec
98
+ - lib/garage_client/rails.rb
99
+ - lib/garage_client/rails/controller_runtime.rb
100
+ - lib/garage_client/rails/log_subscriber.rb
101
+ - lib/garage_client/rails/railtie.rb
102
+ - lib/garage_client/rails/runtime_registry.rb
103
+ - lib/garage_client/rails/version.rb
104
+ - lib/garage_client/request_instrumentable.rb
105
+ homepage: https://github.com/TakatoshiMaeda/garage_client-rails
106
+ licenses: []
107
+ metadata:
108
+ allowed_push_host: https://rubygems.org/
109
+ post_install_message:
110
+ rdoc_options: []
111
+ require_paths:
112
+ - lib
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ requirements: []
124
+ rubyforge_project:
125
+ rubygems_version: 2.4.5
126
+ signing_key:
127
+ specification_version: 4
128
+ summary: GarageClient for rails
129
+ test_files: []