js_rails_routes 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6542396accf937692fb966d1cea9e13b037059fc
4
- data.tar.gz: 2fabec2ed3c39d5b12c9735e0a2e84aaaa39e640
3
+ metadata.gz: ca0f6f4f31f67057a1ae5f4d839b98564d323dfa
4
+ data.tar.gz: 9966df2ec91cc5f7ec03dd6ca082a01a3c73f4d4
5
5
  SHA512:
6
- metadata.gz: 5d0df45754906758a9266abbc7382dc07390e5ad0b06a564883fdf21e3569da2d92797496789dc72331566c3ba76308c427b3430d7cb837a1819ca375cbb7ea2
7
- data.tar.gz: 160bf9a51331d3ecb1809f6f229aff92748d7a3853f3047920d608bdc28c4260fa194c8ce870dd2cb27773f79e4bd00b19812a3a1c8de54d608067a9bb651354
6
+ metadata.gz: 08885b9714f50b48795aab6d79f5ce0e8e32de2ce1c245865a158c14011be5b38024a4d99f7024574b0c431f11907aee16fb5cfc73c34499cc9c845a939ed322
7
+ data.tar.gz: 2143f80a2c1090ce16b4493ccb196a62d0c889930ff1ec5e6fe2ad6fb149b2491e7d4a716f3843f3b5e93285d2cf779a48843f56dc75fbbaeb7441722c48bc6b
data/.gitignore CHANGED
@@ -2,3 +2,4 @@
2
2
  *.gem
3
3
  Gemfile.lock
4
4
  spec/examples.txt
5
+ coverage
data/.rubocop.yml CHANGED
@@ -4,9 +4,16 @@ Metrics/LineLength:
4
4
  Metrics/AbcSize:
5
5
  Max: 20
6
6
 
7
+ Metrics/BlockLength:
8
+ Exclude:
9
+ - 'spec/**/*'
10
+
7
11
  Style/Documentation:
8
12
  Enabled: false
9
13
 
14
+ Style/SymbolArray:
15
+ Enabled: false
16
+
10
17
  Style/TrailingCommaInLiteral:
11
18
  Enabled: false
12
19
 
data/.travis.yml CHANGED
@@ -3,3 +3,8 @@ rvm:
3
3
  - 2.3.1
4
4
  notifications:
5
5
  email: false
6
+ script:
7
+ - bundle exec rake rubocop
8
+ - bundle exec rake spec
9
+ after_success:
10
+ - bundle exec codeclimate-test-reporter
data/CHANGELOG.md CHANGED
@@ -4,7 +4,14 @@ All notable changes to this project will be documented in this file.
4
4
 
5
5
  This change log adheres to [keepachangelog.com](http://keepachangelog.com).
6
6
 
7
- ## [0.3.0]
7
+ ## [0.4.0] - 2017-04-05
8
+ ### Added
9
+ - Add `include_names` and `exclude_names` option
10
+
11
+ ### Changed
12
+ - Rename `includes` and `excludes` as `include_paths` and `exclude_paths` respectively
13
+
14
+ ## [0.3.0] - 2016-06-25
8
15
  ### Added
9
16
  - Enable to configure through Ruby interface
10
17
 
@@ -24,6 +31,7 @@ This change log adheres to [keepachangelog.com](http://keepachangelog.com).
24
31
  ### Added
25
32
  - Implement "js:rails:routes" task
26
33
 
34
+ [0.4.0]: https://github.com/yuku-t/js_rails_routes/compare/v0.3.0...v0.4.0
27
35
  [0.3.0]: https://github.com/yuku-t/js_rails_routes/compare/v0.2.1...v0.3.0
28
36
  [0.2.1]: https://github.com/yuku-t/js_rails_routes/compare/v0.2.0...v0.2.1
29
37
  [0.2.0]: https://github.com/yuku-t/js_rails_routes/compare/v0.1.0...v0.2.0
data/Gemfile CHANGED
@@ -1,4 +1,2 @@
1
1
  source 'https://rubygems.org'
2
2
  gemspec
3
-
4
- gem 'codeclimate-test-reporter', group: :test, require: nil
data/README.md CHANGED
@@ -1,15 +1,20 @@
1
1
  # rake js:routes
2
2
 
3
- [![Gem](https://img.shields.io/gem/v/js_rails_routes.svg?maxAge=2592000)](https://rubygems.org/gems/js_rails_routes) [![Build Status](https://travis-ci.org/yuku-t/js_rails_routes.svg?branch=master)](https://travis-ci.org/yuku-t/js_rails_routes) [![Code Climate](https://codeclimate.com/github/yuku-t/js_rails_routes/badges/gpa.svg)](https://codeclimate.com/github/yuku-t/js_rails_routes) [![Test Coverage](https://codeclimate.com/github/yuku-t/js_rails_routes/badges/coverage.svg)](https://codeclimate.com/github/yuku-t/js_rails_routes/coverage) [![license](https://img.shields.io/github/license/yuku-t/js_rails_routes.svg?maxAge=2592000)](https://github.com/yuku-t/js_rails_routes/blob/master/LICENSE)
3
+ [![Gem](https://img.shields.io/gem/v/js_rails_routes.svg?maxAge=2592000)](https://rubygems.org/gems/js_rails_routes)
4
+ [![Build Status](https://travis-ci.org/yuku-t/js_rails_routes.svg?branch=master)](https://travis-ci.org/yuku-t/js_rails_routes)
5
+ [![Code Climate](https://codeclimate.com/github/yuku-t/js_rails_routes/badges/gpa.svg)](https://codeclimate.com/github/yuku-t/js_rails_routes)
6
+ [![Test Coverage](https://codeclimate.com/github/yuku-t/js_rails_routes/badges/coverage.svg)](https://codeclimate.com/github/yuku-t/js_rails_routes/coverage)
7
+ [![license](https://img.shields.io/github/license/yuku-t/js_rails_routes.svg?maxAge=2592000)](https://github.com/yuku-t/js_rails_routes/blob/master/LICENSE)
8
+ [![Analytics](https://ga-beacon.appspot.com/UA-4932407-14/js_rails_routes/readme)](https://github.com/igrigorik/ga-beacon)
4
9
 
5
10
  Generate a ES6 module that contains Rails routes.
6
11
 
7
12
  ## Description
8
13
 
9
14
  This gem provides "js:routes" rake task.
10
- It generates a ES6 requirable module with exports url helper functions defined by your Rails application.
15
+ It generates a ES6 requirable module which exports url helper functions defined in your Rails application.
11
16
 
12
- Suppose a Rails app has some routes:
17
+ Suppose the app has following routes:
13
18
 
14
19
  ```rb
15
20
  # == Route Map
@@ -28,7 +33,7 @@ Rails.application.routes.draw do
28
33
  end
29
34
  ```
30
35
 
31
- This gem generates a JS file looks like this:
36
+ then `rake js:routes` generates "app/assets/javascripts/rails-routes.js" as:
32
37
 
33
38
  ```js
34
39
  // Don't edit manually. `rake js:routes` generates this file.
@@ -60,19 +65,21 @@ rake js:routes
60
65
 
61
66
  JSRailsRoutes supports several parameters:
62
67
 
63
- Name | Type | Description | Default
64
- -----------|----------|-----------------------------------------|----------------------------------------
65
- `includes` | `Regexp` | routes match to the regexp are included | `/.*/`
66
- `excludes` | `Regexp` | routes match to the regexp are excluded | `/^$/`
67
- `path` | `String` | JS file path | `"app/assets/javascripts/rails-routes.js"`
68
+ Name | Type | Description | Default
69
+ ----------------|----------|-----------------------------------------|----------------------------------------
70
+ `include_paths` | `Regexp` | paths match to the regexp are included | `/.*/`
71
+ `exclude_paths` | `Regexp` | paths match to the regexp are excluded | `/^$/`
72
+ `include_names` | `Regexp` | names match to the regexp are included | `/.*/`
73
+ `exclude_names` | `Regexp` | names match to the regexp are excluded | `/^$/`
74
+ `path` | `String` | JS file path | `Rails.root.join("app", "assets", "javascripts", "rails-routes.js")`
68
75
 
69
76
  You can configure via `JSRailsRoutes.configure`.
70
77
 
71
78
  ```rb
72
79
  # Rakefile
73
- JSRailsRoutes.configure |c|
74
- c.excludes = %r{^/(rails|sidekiq)}
75
- c.path = 'path/to/rails-routes.js'
80
+ JSRailsRoutes.configure do |c|
81
+ c.exclude_paths = %r{^/(rails|sidekiq)}
82
+ c.path = Rails.root.join('path', 'to', 'rails-routes.js')
76
83
  end
77
84
  ```
78
85
 
@@ -83,7 +90,7 @@ Now `rake js:routes` ignores paths starting with "/rails" or "/sidekiq".
83
90
  You can override the coniguration via command line parameters:
84
91
 
85
92
  ```bash
86
- rake js:routes excludes='^/rails'
93
+ rake js:routes exclude_paths='^/rails'
87
94
  ```
88
95
 
89
96
  The command still ignores "/rails" but includes "/sidekiq".
@@ -98,7 +105,7 @@ gem 'js_rails_routes', group: :development
98
105
 
99
106
  ## License
100
107
 
101
- [MIT](https://github.com/yuku-t/js_rails_routes/blob/master/LICENCE)
108
+ [MIT](https://github.com/yuku-t/js_rails_routes/blob/master/LICENSE)
102
109
 
103
110
  ## Author
104
111
 
@@ -14,7 +14,9 @@ Gem::Specification.new do |spec|
14
14
  spec.require_paths = ['lib']
15
15
  spec.add_dependency 'rails', '>= 3.2'
16
16
  spec.add_development_dependency 'bundler', '~> 1.7'
17
+ spec.add_development_dependency 'codeclimate-test-reporter', '~> 1.0'
17
18
  spec.add_development_dependency 'rake', '~> 10.0'
18
19
  spec.add_development_dependency 'rspec', '~> 3.4.0'
19
- spec.add_development_dependency 'rubocop', '~> 0.40.0'
20
+ spec.add_development_dependency 'rubocop', '~> 0.48.1'
21
+ spec.add_development_dependency 'simplecov', '~> 0.14'
20
22
  end
@@ -6,11 +6,13 @@ module JSRailsRoutes
6
6
 
7
7
  include Singleton
8
8
 
9
- attr_accessor :includes, :excludes, :path
9
+ attr_accessor :include_paths, :exclude_paths, :include_names, :exclude_names, :path
10
10
 
11
11
  def initialize
12
- self.includes = /.*/
13
- self.excludes = /^$/
12
+ self.include_paths = /.*/
13
+ self.exclude_paths = /^$/
14
+ self.include_names = /.*/
15
+ self.exclude_names = /^$/
14
16
  self.path = Rails.root.join('app', 'assets', 'javascripts', 'rails-routes.js')
15
17
  Rails.application.reload_routes!
16
18
  end
@@ -26,9 +28,11 @@ module JSRailsRoutes
26
28
 
27
29
  private
28
30
 
29
- def match?(_route_name, route_path)
30
- return false if includes !~ route_path
31
- return false if excludes =~ route_path
31
+ def match?(route_name, route_path)
32
+ return false if include_paths !~ route_path
33
+ return false if exclude_paths =~ route_path
34
+ return false if include_names !~ route_name
35
+ return false if exclude_names =~ route_name
32
36
  true
33
37
  end
34
38
 
@@ -1,3 +1,3 @@
1
1
  module JSRailsRoutes
2
- VERSION = '0.3.0'.freeze
2
+ VERSION = '0.4.0'.freeze
3
3
  end
@@ -2,8 +2,10 @@ desc 'Generate a ES6 module that contains Rails routes'
2
2
  namespace :js do
3
3
  task routes: :environment do |task|
4
4
  generator = JSRailsRoutes::Generator.instance
5
- generator.includes = Regexp.new(ENV['includes']) if ENV['includes']
6
- generator.excludes = Regexp.new(ENV['excludes']) if ENV['excludes']
5
+ generator.include_paths = Regexp.new(ENV['include_paths']) if ENV['include_paths']
6
+ generator.exclude_paths = Regexp.new(ENV['exclude_paths']) if ENV['exclude_paths']
7
+ generator.include_names = Regexp.new(ENV['include_names']) if ENV['include_names']
8
+ generator.exclude_names = Regexp.new(ENV['exclude_names']) if ENV['exclude_names']
7
9
  generator.path = ENV['path'] if ENV['path']
8
10
  generator.generate(task)
9
11
  puts "Routes saved to #{generator.path}."
@@ -19,32 +19,32 @@ RSpec.describe JSRailsRoutes::Generator do
19
19
  subject
20
20
  end
21
21
 
22
- context 'when includes is given' do
22
+ context 'when include_paths is given' do
23
23
  before do
24
- generator.includes = Regexp.new(includes)
24
+ generator.include_paths = include_paths
25
25
  end
26
26
 
27
- let(:includes) do
28
- '/new'
27
+ let(:include_paths) do
28
+ %r{/new}
29
29
  end
30
30
 
31
31
  it 'writes paths matching with the parameter' do
32
32
  expect(generator).to receive(:write).with(a_kind_of(String)) do |arg|
33
33
  paths = arg.split("\n")[1..-1]
34
34
  expect(paths).not_to be_empty
35
- expect(paths).to all(a_string_including(includes))
35
+ expect(paths).to all(match(include_paths))
36
36
  end
37
37
  subject
38
38
  end
39
39
  end
40
40
 
41
- context 'when excludes is given' do
41
+ context 'when exclude_paths is given' do
42
42
  before do
43
- generator.excludes = Regexp.new(excludes)
43
+ generator.exclude_paths = exclude_paths
44
44
  end
45
45
 
46
- let(:excludes) do
47
- '/new'
46
+ let(:exclude_paths) do
47
+ %r{/new}
48
48
  end
49
49
 
50
50
  it 'writes paths not matching with the parameter' do
@@ -52,7 +52,47 @@ RSpec.describe JSRailsRoutes::Generator do
52
52
  paths = arg.split("\n")[1..-1]
53
53
  expect(paths).not_to be_empty
54
54
  paths.each do |path|
55
- expect(path).to_not include(excludes)
55
+ expect(path).to_not match(exclude_paths)
56
+ end
57
+ end
58
+ subject
59
+ end
60
+ end
61
+
62
+ context 'when include_names is given' do
63
+ before do
64
+ generator.include_names = include_names
65
+ end
66
+
67
+ let(:include_names) do
68
+ /user/
69
+ end
70
+
71
+ it 'writes paths matching with the parameter' do
72
+ expect(generator).to receive(:write).with(a_kind_of(String)) do |arg|
73
+ paths = arg.split("\n")[1..-1]
74
+ expect(paths).not_to be_empty
75
+ expect(paths).to all(match(include_names))
76
+ end
77
+ subject
78
+ end
79
+ end
80
+
81
+ context 'when exclude_names is given' do
82
+ before do
83
+ generator.exclude_names = exclude_names
84
+ end
85
+
86
+ let(:exclude_names) do
87
+ /user/
88
+ end
89
+
90
+ it 'writes paths not matching with the parameter' do
91
+ expect(generator).to receive(:write).with(a_kind_of(String)) do |arg|
92
+ paths = arg.split("\n")[1..-1]
93
+ expect(paths).not_to be_empty
94
+ paths.each do |path|
95
+ expect(path).to_not match(exclude_names)
56
96
  end
57
97
  end
58
98
  subject
data/spec/spec_helper.rb CHANGED
@@ -1,22 +1,21 @@
1
1
  $LOAD_PATH << File.expand_path('../../lib', __FILE__)
2
2
 
3
- require 'codeclimate-test-reporter'
4
- CodeClimate::TestReporter.start
3
+ require 'simplecov'
4
+ SimpleCov.start
5
5
 
6
6
  require 'rails/all'
7
7
  require 'js_rails_routes'
8
8
 
9
9
  class TestApp < Rails::Application
10
10
  config.root = File.expand_path('../test_app', __FILE__)
11
- end
12
11
 
13
- RSpec.configure do |config|
14
- config.before :all do
15
- TestApp.routes.draw do
16
- resources :apps
17
- end
12
+ routes.draw do
13
+ resources :blogs
14
+ resources :users
18
15
  end
16
+ end
19
17
 
18
+ RSpec.configure do |config|
20
19
  config.expect_with :rspec do |expectations|
21
20
  expectations.include_chain_clauses_in_custom_matcher_descriptions = true
22
21
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: js_rails_routes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yuku Takahashi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-25 00:00:00.000000000 Z
11
+ date: 2017-04-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.7'
41
+ - !ruby/object:Gem::Dependency
42
+ name: codeclimate-test-reporter
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: rake
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -72,14 +86,28 @@ dependencies:
72
86
  requirements:
73
87
  - - "~>"
74
88
  - !ruby/object:Gem::Version
75
- version: 0.40.0
89
+ version: 0.48.1
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 0.48.1
97
+ - !ruby/object:Gem::Dependency
98
+ name: simplecov
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0.14'
76
104
  type: :development
77
105
  prerelease: false
78
106
  version_requirements: !ruby/object:Gem::Requirement
79
107
  requirements:
80
108
  - - "~>"
81
109
  - !ruby/object:Gem::Version
82
- version: 0.40.0
110
+ version: '0.14'
83
111
  description:
84
112
  email:
85
113
  - taka84u9@gmail.com