grape-raketasks 0.0.1 → 0.0.2
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 +4 -4
- data/.rspec +2 -0
- data/.rubocop.yml +22 -0
- data/.travis.yml +18 -0
- data/Gemfile +1 -0
- data/README.md +29 -16
- data/Rakefile +19 -0
- data/grape-raketasks.gemspec +5 -6
- data/lib/grape-raketasks/console_formatter.rb +11 -6
- data/lib/grape-raketasks/processor.rb +14 -4
- data/lib/grape-raketasks/route.rb +4 -3
- data/lib/grape-raketasks/tasks.rb +0 -1
- data/lib/grape-raketasks/version.rb +1 -2
- data/lib/grape-raketasks.rb +0 -1
- data/lib/tasks/grape-raketasks.rake +3 -3
- data/spec/grape-raketasks/console_formatter_spec.rb +5 -6
- data/spec/grape-raketasks/processor_spec.rb +24 -5
- data/spec/grape-raketasks/route_spec.rb +1 -1
- data/spec/spec_helper.rb +0 -1
- data/spec/support/test_objects.rb +6 -4
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b36e73fad304800dd400fb2778fdfb7a92aaec3f
|
4
|
+
data.tar.gz: 37f8ca1dd7db650aed3b777dd90b3df0a531ff6e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9a7d2ef78f84c8461a664c374eace6762716f06d8a25066f4d412e082ea08975bc5be25b7df94bf718a59550fde89cb4c6fd4381500586e57917675b679d80be
|
7
|
+
data.tar.gz: 1dd7e4e72181f900a4b4894cdbf0e91910e6fe1db1d592cf0504fc83d6acd543e827c68b2cf7ed3e6a68238ddafdc38cc2d9dca90c74b96fa347f6dec70715fb
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
AllCops:
|
2
|
+
Exclude:
|
3
|
+
- vendor/**/*
|
4
|
+
- bin/**/*
|
5
|
+
|
6
|
+
Documentation:
|
7
|
+
Enabled: false
|
8
|
+
|
9
|
+
LineLength:
|
10
|
+
Enabled: false
|
11
|
+
|
12
|
+
MethodLength:
|
13
|
+
Enabled: true
|
14
|
+
|
15
|
+
ClassLength:
|
16
|
+
Enabled: false
|
17
|
+
|
18
|
+
FileName:
|
19
|
+
Enabled: false
|
20
|
+
|
21
|
+
Encoding:
|
22
|
+
Enabled: false
|
data/.travis.yml
ADDED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -2,6 +2,8 @@
|
|
2
2
|
|
3
3
|
Rake tasks to ease the development and debugging of Grape APIs.
|
4
4
|
|
5
|
+
[](https://travis-ci.org/reprah/grape-raketasks)
|
6
|
+
|
5
7
|
## Available Tasks
|
6
8
|
|
7
9
|
### Routes
|
@@ -10,15 +12,27 @@ Rake tasks to ease the development and debugging of Grape APIs.
|
|
10
12
|
|
11
13
|
#### Filtering
|
12
14
|
|
13
|
-
If you want to see routes belonging to only one API
|
15
|
+
If you want to see routes belonging to only one API:
|
16
|
+
|
17
|
+
Pass an environment variable set to your API name after writing the task. Given the API below, and assuming we only want to see routes belonging to this CatPictures API...
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
module CatPictures
|
21
|
+
class API < Grape::API
|
22
|
+
# API stuff
|
23
|
+
end
|
24
|
+
end
|
25
|
+
```
|
26
|
+
|
27
|
+
I'd execute `rake grape_raketasks:routes API=CatPictures::API`. Notice how we have to list which constants the API is nested in (if any), separated by a double colon, like in Ruby code.
|
14
28
|
|
15
29
|
## Installation
|
16
30
|
|
17
|
-
1.) grape-raketasks
|
31
|
+
1.) Add `grape-raketasks` to your Gemfile:
|
18
32
|
|
19
33
|
```ruby
|
20
34
|
# Gemfile
|
21
|
-
gem 'grape-raketasks'
|
35
|
+
gem 'grape-raketasks'
|
22
36
|
```
|
23
37
|
|
24
38
|
2.) Install the gem via Bundler:
|
@@ -26,7 +40,11 @@ gem 'grape-raketasks', git: 'git://github.com/reprah/grape-raketasks'
|
|
26
40
|
```shell
|
27
41
|
$ bundle install
|
28
42
|
```
|
29
|
-
|
43
|
+
or on the command line:
|
44
|
+
|
45
|
+
```shell
|
46
|
+
$ gem install grape-raketasks
|
47
|
+
```
|
30
48
|
|
31
49
|
3.) If your Grape APIs are defined in a Sinatra or Rack web application, you need to write a rake task called `:environment`that loads the application's environment first. This gem's tasks are dependent on it. You could put this in the root of your project directory:
|
32
50
|
|
@@ -34,7 +52,7 @@ If you don't want to use Bundler, follow the [instructions here](http://ruby.abo
|
|
34
52
|
# Rakefile
|
35
53
|
|
36
54
|
require 'rake'
|
37
|
-
require 'bundler'
|
55
|
+
require 'bundler'
|
38
56
|
Bundler.setup
|
39
57
|
require 'grape-raketasks'
|
40
58
|
require 'grape-raketasks/tasks'
|
@@ -52,17 +70,12 @@ Rails applications with mounted Grape APIs don't require an extra step here.
|
|
52
70
|
|
53
71
|
## Contributing
|
54
72
|
|
55
|
-
1.
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
4.) Commit your changes (`git commit -am 'Add some feature'`)
|
62
|
-
|
63
|
-
5.) Push to the branch (`git push origin my-new-feature`)
|
64
|
-
|
65
|
-
6.) Create a new pull request
|
73
|
+
1. Fork it
|
74
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
75
|
+
3. Write specs for your feature
|
76
|
+
4. Commit your changes (`git commit -am 'Add some feature'`)
|
77
|
+
5. Push to the branch (`git push origin my-new-feature`)
|
78
|
+
6. Create a new pull request
|
66
79
|
|
67
80
|
## License
|
68
81
|
|
data/Rakefile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
|
4
|
+
Bundler.setup :default, :test, :development
|
5
|
+
|
6
|
+
Bundler::GemHelper.install_tasks
|
7
|
+
|
8
|
+
require 'rspec/core/rake_task'
|
9
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
10
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
11
|
+
end
|
12
|
+
|
13
|
+
task :spec
|
14
|
+
|
15
|
+
require 'rainbow/ext/string' unless String.respond_to?(:color)
|
16
|
+
require 'rubocop/rake_task'
|
17
|
+
Rubocop::RakeTask.new(:rubocop)
|
18
|
+
|
19
|
+
task default: [:rubocop, :spec]
|
data/grape-raketasks.gemspec
CHANGED
@@ -2,7 +2,7 @@ require File.dirname(__FILE__) + '/lib/grape-raketasks/version'
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |gem|
|
4
4
|
gem.name = 'grape-raketasks'
|
5
|
-
gem.version = GrapeRakeTasks::VERSION
|
5
|
+
gem.version = GrapeRakeTasks::VERSION
|
6
6
|
|
7
7
|
gem.homepage = 'https://github.com/reprah/grape-raketasks'
|
8
8
|
gem.license = 'MIT'
|
@@ -10,13 +10,12 @@ Gem::Specification.new do |gem|
|
|
10
10
|
gem.description = 'Provides rake tasks to ease the development and debugging of Grape APIs.'
|
11
11
|
gem.author = 'H. Henn'
|
12
12
|
|
13
|
-
gem.files = `git ls-files`.split(
|
13
|
+
gem.files = `git ls-files`.split($OUTPUT_RECORD_SEPARATOR)
|
14
14
|
gem.test_files = gem.files.grep(/^spec/)
|
15
15
|
|
16
|
-
gem.add_runtime_dependency
|
17
|
-
gem.add_runtime_dependency
|
18
|
-
gem.add_runtime_dependency
|
16
|
+
gem.add_runtime_dependency 'grape'
|
17
|
+
gem.add_runtime_dependency 'rake'
|
18
|
+
gem.add_runtime_dependency 'activesupport'
|
19
19
|
|
20
20
|
gem.add_development_dependency 'rspec'
|
21
21
|
end
|
22
|
-
|
@@ -12,14 +12,19 @@ module GrapeRakeTasks
|
|
12
12
|
buffer.join << "\n\n"
|
13
13
|
end
|
14
14
|
|
15
|
-
def construct_output(routes)
|
15
|
+
def construct_output(routes, filter = nil)
|
16
16
|
if routes.any?
|
17
|
-
buffer << routes
|
17
|
+
buffer << formatted_routes(routes)
|
18
18
|
else
|
19
|
-
buffer << no_routes_message
|
19
|
+
buffer << no_routes_message(filter)
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
+
def formatted_routes(routes)
|
24
|
+
formatted = routes.map { |r| format_route(r) }
|
25
|
+
formatted.join("\n\n")
|
26
|
+
end
|
27
|
+
|
23
28
|
def format_route(route)
|
24
29
|
opts = route.options
|
25
30
|
# two characters (colon + space) after the title
|
@@ -43,12 +48,12 @@ module GrapeRakeTasks
|
|
43
48
|
key.to_s.upcase.concat(': ')
|
44
49
|
end
|
45
50
|
|
46
|
-
def no_routes_message
|
51
|
+
def no_routes_message(filter)
|
52
|
+
subject = filter ? filter : 'your application'
|
47
53
|
<<-MSG.strip_heredoc
|
48
|
-
You don't have any Grape routes defined
|
54
|
+
You don't have any Grape routes defined for #{subject}.
|
49
55
|
Visit https://github.com/intridea/grape for help.
|
50
56
|
MSG
|
51
57
|
end
|
52
58
|
end
|
53
59
|
end
|
54
|
-
|
@@ -10,15 +10,25 @@ module GrapeRakeTasks
|
|
10
10
|
|
11
11
|
def format(formatter, filter = nil)
|
12
12
|
routes_to_display = filter_by_api(filter)
|
13
|
-
formatter.construct_output(routes_to_display)
|
13
|
+
formatter.construct_output(routes_to_display, filter)
|
14
14
|
formatter.result
|
15
15
|
end
|
16
16
|
|
17
17
|
def filter_by_api(filter = nil)
|
18
18
|
return routes unless filter
|
19
|
-
|
20
|
-
routes.select
|
19
|
+
pattern = Regexp.new(filter, Regexp::IGNORECASE)
|
20
|
+
filtered = routes.select do |r|
|
21
|
+
matches_filter_pattern?(r, pattern)
|
22
|
+
end
|
23
|
+
filtered.uniq
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def matches_filter_pattern?(route, pattern)
|
29
|
+
# match filter against string representation of a route's API
|
30
|
+
api_as_string = route.route_api.to_s
|
31
|
+
api_as_string.match(pattern)
|
21
32
|
end
|
22
33
|
end
|
23
34
|
end
|
24
|
-
|
@@ -1,8 +1,10 @@
|
|
1
1
|
require 'active_support/core_ext/class'
|
2
2
|
|
3
3
|
# enable adding the API name to a route's options
|
4
|
-
|
5
|
-
|
4
|
+
module Grape
|
5
|
+
class Route
|
6
|
+
attr_accessor :options
|
7
|
+
end
|
6
8
|
end
|
7
9
|
|
8
10
|
module GrapeRakeTasks
|
@@ -26,4 +28,3 @@ module GrapeRakeTasks
|
|
26
28
|
end
|
27
29
|
end
|
28
30
|
end
|
29
|
-
|
data/lib/grape-raketasks.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
namespace :grape_raketasks do
|
2
|
-
desc 'Print routes provided by Grape APIs to the terminal. Target a specific API with
|
2
|
+
desc 'Print routes provided by Grape APIs to the terminal. Target a specific API with API=x.'
|
3
3
|
task routes: :environment do
|
4
4
|
all_routes = GrapeRakeTasks::Route.all_routes(Grape::API)
|
5
|
-
|
6
|
-
puts
|
5
|
+
processor = GrapeRakeTasks::Processor.new(all_routes)
|
6
|
+
puts processor.format(GrapeRakeTasks::ConsoleFormatter.new, ENV['API'])
|
7
7
|
end
|
8
8
|
end
|
9
9
|
|
@@ -5,19 +5,19 @@ describe GrapeRakeTasks::ConsoleFormatter do
|
|
5
5
|
|
6
6
|
describe '#construct_output' do
|
7
7
|
before do
|
8
|
-
formatter.stub(format_route: 'formatted route')
|
8
|
+
formatter.stub(format_route: 'formatted route')
|
9
9
|
end
|
10
10
|
|
11
11
|
context 'when routes exist' do
|
12
12
|
before do
|
13
|
-
formatter.construct_output(['a route'])
|
13
|
+
formatter.construct_output(['a route'])
|
14
14
|
end
|
15
15
|
|
16
16
|
it 'adds formatted routes to the buffer' do
|
17
17
|
expect(formatter.buffer).to include('formatted route')
|
18
18
|
end
|
19
19
|
end
|
20
|
-
|
20
|
+
|
21
21
|
context 'when no routes exist' do
|
22
22
|
before do
|
23
23
|
formatter.construct_output([])
|
@@ -25,7 +25,7 @@ describe GrapeRakeTasks::ConsoleFormatter do
|
|
25
25
|
|
26
26
|
it 'adds a message to the buffer' do
|
27
27
|
msg = formatter.buffer.first
|
28
|
-
expect(msg).to include("You don't have any Grape routes
|
28
|
+
expect(msg).to include("You don't have any Grape routes")
|
29
29
|
end
|
30
30
|
end
|
31
31
|
end
|
@@ -35,7 +35,7 @@ describe GrapeRakeTasks::ConsoleFormatter do
|
|
35
35
|
|
36
36
|
it 'returns a text representation of a route object' do
|
37
37
|
result = formatter.format_route(route_object)
|
38
|
-
expect(result).to match(/METHOD:\s+"GET"/)
|
38
|
+
expect(result).to match(/METHOD:\s+"GET"/)
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
@@ -49,4 +49,3 @@ describe GrapeRakeTasks::ConsoleFormatter do
|
|
49
49
|
end
|
50
50
|
end
|
51
51
|
end
|
52
|
-
|
@@ -8,16 +8,36 @@ describe GrapeRakeTasks::Processor do
|
|
8
8
|
|
9
9
|
let(:processor) { described_class.new(routes) }
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
it 'returns only routes belonging to that API' do
|
11
|
+
shared_examples 'successful API filtering' do
|
12
|
+
it 'returns routes belonging to one API' do
|
15
13
|
filtered = processor.filter_by_api(filter)
|
16
14
|
filtered_apis = filtered.map(&:route_api)
|
17
15
|
expect(filtered_apis).to eq [SampleApiOne::API]
|
18
16
|
end
|
19
17
|
end
|
20
18
|
|
19
|
+
context 'when given a Grape API to filter by' do
|
20
|
+
let(:filter) { 'SampleAPIOne::API' }
|
21
|
+
|
22
|
+
it_behaves_like 'successful API filtering'
|
23
|
+
|
24
|
+
context "when filter's case does not exactly match an API" do
|
25
|
+
let(:filter) { 'SampleApiOne::API' }
|
26
|
+
|
27
|
+
it_behaves_like 'successful API filtering'
|
28
|
+
end
|
29
|
+
|
30
|
+
context 'when API is not nested within another constant' do
|
31
|
+
let(:filter) { 'SampleAPIThree' }
|
32
|
+
|
33
|
+
it 'returns routes belonging to that api' do
|
34
|
+
filtered = processor.filter_by_api(filter)
|
35
|
+
filtered_apis = filtered.map(&:route_api)
|
36
|
+
expect(filtered_apis).to include(SampleApiThree)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
21
41
|
context 'when no filter is given' do
|
22
42
|
it 'returns routes from every Grape API' do
|
23
43
|
unfiltered = processor.filter_by_api
|
@@ -27,4 +47,3 @@ describe GrapeRakeTasks::Processor do
|
|
27
47
|
end
|
28
48
|
end
|
29
49
|
end
|
30
|
-
|
@@ -15,7 +15,7 @@ describe GrapeRakeTasks::Route do
|
|
15
15
|
|
16
16
|
it 'returns a collection of routes that know their parent API' do
|
17
17
|
routes = described_class.api_routes(SampleApiOne::API)
|
18
|
-
every_route_has_api = routes.all? { |r| r.options.
|
18
|
+
every_route_has_api = routes.all? { |r| r.options.key?(:api) }
|
19
19
|
expect(every_route_has_api).to be_true
|
20
20
|
end
|
21
21
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -6,17 +6,19 @@ def grape_route_object
|
|
6
6
|
g
|
7
7
|
end
|
8
8
|
|
9
|
-
|
9
|
+
module SampleApiOne
|
10
10
|
class API < Grape::API
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
-
|
14
|
+
module SampleApiTwo
|
15
15
|
class API < Grape::API
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
-
|
20
|
-
api.routes << grape_route_object
|
19
|
+
class SampleApiThree < Grape::API
|
21
20
|
end
|
22
21
|
|
22
|
+
Grape::API.subclasses.each do |api|
|
23
|
+
api.routes << grape_route_object
|
24
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: grape-raketasks
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- H. Henn
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-06-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: grape
|
@@ -73,9 +73,13 @@ extensions: []
|
|
73
73
|
extra_rdoc_files: []
|
74
74
|
files:
|
75
75
|
- .gitignore
|
76
|
+
- .rspec
|
77
|
+
- .rubocop.yml
|
78
|
+
- .travis.yml
|
76
79
|
- Gemfile
|
77
80
|
- LICENSE
|
78
81
|
- README.md
|
82
|
+
- Rakefile
|
79
83
|
- grape-raketasks.gemspec
|
80
84
|
- lib/grape-raketasks.rb
|
81
85
|
- lib/grape-raketasks/console_formatter.rb
|