passages 1.4.0 → 1.4.1

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: ca4bb9df54319e3bd96465b6b28bfad0ace42970
4
- data.tar.gz: 8af7f485c8eb5dd4cc09ac5f8956c0df720b824c
3
+ metadata.gz: 67624b8b5e3463b0f208b14a7b83b07e2bec4ce8
4
+ data.tar.gz: 9b5f496d76095f08336886d7eee03ac48604e5f0
5
5
  SHA512:
6
- metadata.gz: ef7b145f7cbbd63e91c7eb6c5a626512c9a69e284f0b5d7fd0a962e711c979b13b9467a17c2353b3d74b4d8739dec73ecb3b211bbb35797f2128538814cefad1
7
- data.tar.gz: cf7469e8ab678be9a644c0fd0f741e64a22959968c108153686072744e7d7bd38d7fae67cd98c516f576e49946de9726910dec9e2907eeabc7dcdf8193224b42
6
+ metadata.gz: 6ac021c052780b84ba0139bdd6043a875b98396d855f411c224d31309b0469cdd2895930ac6705582322e614cf8c94404d5921139e3ed2c0db509c92b017172a
7
+ data.tar.gz: cc6056f8aadc10df93ec9b52f55194707e9063b57532566fe5b815be41b60dfe9abda08792ca7edc23ae7ad69fe22c87e30c7e8dd97627ae93771668fbb00c39
data/.travis.yml CHANGED
@@ -5,4 +5,6 @@ rvm:
5
5
  - 2.2.2
6
6
  - 2.3.0
7
7
 
8
- script: bundle exec rspec spec
8
+ script:
9
+ - bundle exec rspec spec
10
+ - bundle exec rubocop
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- passages (1.3.0)
4
+ passages (1.4.0)
5
5
  rails (~> 4.0)
6
6
 
7
7
  GEM
@@ -43,6 +43,7 @@ GEM
43
43
  thread_safe (~> 0.3, >= 0.3.4)
44
44
  tzinfo (~> 1.1)
45
45
  arel (6.0.3)
46
+ ast (2.2.0)
46
47
  builder (3.2.2)
47
48
  diff-lcs (1.2.5)
48
49
  erubis (2.7.0)
@@ -56,9 +57,12 @@ GEM
56
57
  mime-types (>= 1.16, < 3)
57
58
  mime-types (2.6.2)
58
59
  mini_portile (0.6.2)
59
- minitest (5.8.1)
60
+ minitest (5.8.3)
60
61
  nokogiri (1.6.6.2)
61
62
  mini_portile (~> 0.6.0)
63
+ parser (2.3.0.7)
64
+ ast (~> 2.2)
65
+ powerpack (0.1.1)
62
66
  rack (1.6.4)
63
67
  rack-test (0.6.3)
64
68
  rack (>= 1.0)
@@ -86,6 +90,7 @@ GEM
86
90
  activesupport (= 4.2.4)
87
91
  rake (>= 0.8.7)
88
92
  thor (>= 0.18.1, < 2.0)
93
+ rainbow (2.1.0)
89
94
  rake (10.4.2)
90
95
  rspec (3.3.0)
91
96
  rspec-core (~> 3.3.0)
@@ -100,6 +105,13 @@ GEM
100
105
  diff-lcs (>= 1.2.0, < 2.0)
101
106
  rspec-support (~> 3.3.0)
102
107
  rspec-support (3.3.0)
108
+ rubocop (0.39.0)
109
+ parser (>= 2.3.0.7, < 3.0)
110
+ powerpack (~> 0.1)
111
+ rainbow (>= 1.99.1, < 3.0)
112
+ ruby-progressbar (~> 1.7)
113
+ unicode-display_width (~> 1.0, >= 1.0.1)
114
+ ruby-progressbar (1.7.5)
103
115
  sprockets (3.3.5)
104
116
  rack (> 1, < 3)
105
117
  sprockets-rails (2.3.3)
@@ -110,6 +122,7 @@ GEM
110
122
  thread_safe (0.3.5)
111
123
  tzinfo (1.2.2)
112
124
  thread_safe (~> 0.1)
125
+ unicode-display_width (1.0.2)
113
126
 
114
127
  PLATFORMS
115
128
  ruby
@@ -117,3 +130,7 @@ PLATFORMS
117
130
  DEPENDENCIES
118
131
  passages!
119
132
  rspec (~> 3.2)
133
+ rubocop (= 0.39.0)
134
+
135
+ BUNDLED WITH
136
+ 1.11.2
@@ -5,6 +5,8 @@ require 'passages/route_collection'
5
5
  require 'passages/engine_route_collection'
6
6
 
7
7
  module Passages
8
+ # Single Rails controller responsible for
9
+ # collecting instance variables and rendering the Engine's main page
8
10
  class RoutesController < ActionController::Base
9
11
  layout false
10
12
 
@@ -28,20 +30,24 @@ module Passages
28
30
 
29
31
  def mounted_engine_routes
30
32
  @mounted_engine_routes ||= ::Rails::Engine.subclasses.map do |engine|
31
- routes = engine.routes.routes.routes.map { |route| EngineRoute.new(route, engine.name) }
33
+ routes = engine.routes.routes.routes.map do |route|
34
+ EngineRoute.new(route, engine.name)
35
+ end
32
36
 
33
37
  { engine: engine.name, routes: routes }
34
38
  end.compact
35
39
  end
36
40
 
37
41
  def passages_rails_routes
38
- @passages_rails_routes ||= Rails.application.routes.routes.map { |route| Route.from_raw_route(route) }
42
+ @passages_rails_routes ||= Rails.application.routes.routes.map do |route|
43
+ Route.from_raw_route(route)
44
+ end
39
45
  end
40
46
 
41
47
  def mount_routes
42
- {}.tap do |_mount_routes|
48
+ {}.tap do |mount_route_hash|
43
49
  passages_rails_routes.each do |route|
44
- _mount_routes[route.engine_name] = route if route.is_a?(MountRoute)
50
+ mount_route_hash[route.engine_name] = route if route.is_a?(MountRoute)
45
51
  end
46
52
  end
47
53
  end
data/config/config.rb CHANGED
@@ -1,10 +1,12 @@
1
+ # Define the Passages namespace
1
2
  module Passages
3
+ # Central configuration class
2
4
  class Config
3
5
  attr_accessor :automount
4
6
  attr_writer :no_auth
5
7
 
6
8
  def no_auth?
7
- !!@no_auth
9
+ @no_auth.present?
8
10
  end
9
11
  end
10
12
 
@@ -1,3 +1,5 @@
1
+ # Authentication methods that access environment variables
2
+ # and expose config.no_auth?
1
3
  module Passages
2
4
  def username
3
5
  ENV['passages_username'] || ENV['PASSAGES_USERNAME'] || 'username'
@@ -1,12 +1,21 @@
1
1
  module Passages
2
+ # Engine class, subclass of Rails::Engine and the heart of
3
+ # namespace isolation, asset precompiliation hooks and
4
+ # authentication concerns.
2
5
  class Engine < ::Rails::Engine
3
6
  isolate_namespace Passages
4
7
 
5
- initializer "passages.assets.precompile" do |app|
8
+ # Necessary for rake assets:precompile in a main application
9
+ # to compile this Engine's assets as well
10
+ initializer 'passages.assets.precompile' do |app|
6
11
  app.config.assets.precompile += %w(application.css application.js)
7
12
  end
8
13
 
9
- initializer 'passages', after: :load_config_initializers do |app|
14
+ # Optionally mount the /passages route at an applications top
15
+ # level.
16
+ #
17
+ # Optionally allow basic authentication
18
+ initializer 'passages', after: :load_config_initializers do
10
19
  if Passages.config.automount
11
20
  Rails.application.routes.prepend do
12
21
  mount Passages::Engine, at: '/passages'
@@ -14,7 +23,9 @@ module Passages
14
23
  end
15
24
 
16
25
  unless Passages.config.no_auth?
17
- Passages::RoutesController.http_basic_authenticate_with name: Passages.username, password: Passages.password
26
+ Passages::RoutesController.http_basic_authenticate_with(
27
+ name: Passages.username,
28
+ password: Passages.password)
18
29
  end
19
30
  end
20
31
  end
@@ -1,6 +1,7 @@
1
1
  require 'active_support/core_ext'
2
2
 
3
3
  module Passages
4
+ # DelegateClass of internal RouteWrapper class within ActionDispatch
4
5
  class EngineRoute < DelegateClass(ActionDispatch::Routing::RouteWrapper)
5
6
  attr_reader :engine_name
6
7
 
@@ -2,9 +2,11 @@ require_relative 'route'
2
2
  require_relative 'route_collection'
3
3
 
4
4
  module Passages
5
+ # Specialized collection class inherited from RouteCollection specifically
6
+ # for routes of Engines (this Engine included)
5
7
  class EngineRouteCollection < RouteCollection
6
- def initialize(_routes)
7
- @routes = _routes.reject { |h| h[:routes].all?(&:internal?) }
8
+ def initialize(routes)
9
+ @routes = routes.reject { |h| h[:routes].all?(&:internal?) }
8
10
  end
9
11
  end
10
12
  end
@@ -1,4 +1,6 @@
1
1
  module Passages
2
+ # Special DelegateClass of ActionDispatch's RouteWrapper for
3
+ # an Engine's mount route. i.e. /passages for this Engine
2
4
  class MountRoute < DelegateClass(ActionDispatch::Routing::RouteWrapper)
3
5
  def initialize(route, app)
4
6
  @app = app
@@ -3,15 +3,16 @@ require 'action_dispatch/routing/inspector'
3
3
  require_relative 'mount_route'
4
4
 
5
5
  module Passages
6
+ # Main DelegateClass used for decoration and discerning if a route is
7
+ # a "regular" route or a mount route
6
8
  class Route < DelegateClass(ActionDispatch::Routing::RouteWrapper)
7
-
8
9
  def initialize(route)
9
10
  super(ActionDispatch::Routing::RouteWrapper.new(route))
10
11
  end
11
12
 
12
13
  class << self
13
14
  def attributes_for_display
14
- %w[name verb controller action path]
15
+ %w(name verb controller action path)
15
16
  end
16
17
 
17
18
  def from_raw_route(raw_route)
@@ -29,16 +30,20 @@ module Passages
29
30
  def mount_route_class(route)
30
31
  route_app = route.app
31
32
 
32
- app = if route_app.class == Class
33
- route_app
34
- else
35
- route_app.try(:app)
36
- end
37
-
38
- app if app.ancestors.include?(Rails::Engine)
33
+ app(route_app) if app(route_app).ancestors.include?(Rails::Engine)
39
34
  rescue
40
35
  nil
41
36
  end
37
+
38
+ def app(route_app)
39
+ @app ||= begin
40
+ if route_app.class == Class
41
+ route_app
42
+ else
43
+ route_app.try(:app)
44
+ end
45
+ end
46
+ end
42
47
  end
43
48
  end
44
49
  end
@@ -1,13 +1,15 @@
1
1
  require_relative 'route'
2
2
 
3
3
  module Passages
4
+ # Enumerable to iterate through and select only external routes
5
+ # for the main application to display
4
6
  class RouteCollection
5
7
  include Enumerable
6
8
 
7
9
  attr_reader :routes
8
10
 
9
- def initialize(_routes)
10
- @routes = _routes.reject { |r| r.internal? }
11
+ def initialize(routes)
12
+ @routes = routes.reject(&:internal?)
11
13
  end
12
14
 
13
15
  def each(&block)
data/lib/passages.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  $LOAD_PATH << File.dirname(__FILE__) + '/../lib'
2
2
  $LOAD_PATH << File.dirname(__FILE__) + '/../config'
3
3
 
4
+ # Define the Passages namespace module
4
5
  module Passages
5
6
  end
6
7
 
data/passages.gemspec CHANGED
@@ -6,8 +6,11 @@ require './version'
6
6
  Gem::Specification.new do |s|
7
7
  s.name = 'passages'
8
8
  s.version = Passages::VERSION
9
- s.summary = %q{Display and search capabilities for Ruby on Rails routes}
10
- s.description = %q{Rails Engine to make internal routes searchable and discoverable for more than just the name of the route. All aspects of a route are searchable from the HTTP verb to the paramters a route supports.}
9
+ s.summary = 'Display and search capabilities for Ruby on Rails routes'
10
+ s.description = 'Rails Engine to make internal routes searchable and
11
+ discoverable for more than just the name of the route.
12
+ All aspects of a route are searchable from the HTTP
13
+ verb to the paramters a route supports.'
11
14
  s.authors = ['Jake Yesbeck']
12
15
  s.email = 'yesbeckjs@gmail.com'
13
16
  s.homepage = 'https://github.com/yez/passages'
@@ -15,10 +18,11 @@ Gem::Specification.new do |s|
15
18
 
16
19
  s.require_paths = %w(lib app)
17
20
  s.files = `git ls-files`.split("\n")
18
- s.test_files = s.files.grep(/^spec\//)
21
+ s.test_files = s.files.grep(%r{^spec/})
19
22
 
20
23
  s.required_ruby_version = '>= 2.0.0'
21
24
  s.add_dependency 'rails', '~> 4.0'
22
25
 
23
26
  s.add_development_dependency 'rspec', '~> 3.2'
27
+ s.add_development_dependency 'rubocop', '0.39.0'
24
28
  end
@@ -3,18 +3,18 @@ require 'spec_helper'
3
3
  module Passages
4
4
  describe Config do
5
5
  describe '#no_auth?' do
6
- context '@basic_auth is a truthy value' do
6
+ context '@no_auth is a truthy value' do
7
7
  [true, 'yes', ['1'], { a: :b }].each do |value|
8
- it "#{ value } returns true" do
8
+ it "#{value} returns true" do
9
9
  Passages.config.no_auth = value
10
10
  expect(Passages.config.no_auth?).to eq(true)
11
11
  end
12
12
  end
13
13
  end
14
14
 
15
- context '@basic_auth is a falsey value' do
15
+ context '@no_auth is a falsey value' do
16
16
  [false, nil].each do |value|
17
- it "#{ value } returns false" do
17
+ it "#{value} returns false" do
18
18
  Passages.config.no_auth = value
19
19
  expect(Passages.config.no_auth?).to eq(false)
20
20
  end
@@ -16,7 +16,9 @@ describe Passages do
16
16
  let(:upper_username) { 'THISISANUPPERUSERNAME' }
17
17
  before do
18
18
  allow(ENV).to receive(:[]).with('passages_username') { nil }
19
- allow(ENV).to receive(:[]).with('PASSAGES_USERNAME') { upper_username }
19
+ allow(ENV).to receive(:[]).with('PASSAGES_USERNAME') do
20
+ upper_username
21
+ end
20
22
  end
21
23
 
22
24
  it 'uses the ENV var' do
@@ -47,7 +49,9 @@ describe Passages do
47
49
  let(:upper_password) { 'THISISANUPPERPASSWORD' }
48
50
  before do
49
51
  allow(ENV).to receive(:[]).with('passages_password') { nil }
50
- allow(ENV).to receive(:[]).with('PASSAGES_PASSWORD') { upper_password }
52
+ allow(ENV).to receive(:[]).with('PASSAGES_PASSWORD') do
53
+ upper_password
54
+ end
51
55
  end
52
56
 
53
57
  it 'uses the ENV var' do
@@ -7,7 +7,6 @@ require_relative '../../../app/controllers/passages/routes_controller'
7
7
 
8
8
  module Passages
9
9
  describe RoutesController do
10
-
11
10
  describe '#routes' do
12
11
  before do
13
12
  allow(subject).to receive(:application_routes) { anything }
@@ -38,7 +37,10 @@ module Passages
38
37
 
39
38
  describe '!#passages_rails_routes' do
40
39
  it 'calls deep into the Rails routes' do
41
- expect(Rails).to receive_message_chain(:application, :routes, :routes) { [] }
40
+ expect(Rails)
41
+ .to receive_message_chain(:application, :routes, :routes) do
42
+ []
43
+ end
42
44
  subject.send(:passages_rails_routes)
43
45
  end
44
46
  end
@@ -13,10 +13,14 @@ module Passages
13
13
  allow(fake_route).to receive(:internal?) { false }
14
14
  end
15
15
 
16
- subject { described_class.new([{engine: engine_name, routes: [fake_route]}]) }
16
+ subject do
17
+ described_class.new([{ engine: engine_name, routes: [fake_route] }])
18
+ end
17
19
 
18
20
  it 'adds the engine name to each route' do
19
- expect(subject.routes.all? { |route| route[:engine] == engine_name }).to eq(true)
21
+ expect(subject.routes).to be_all do |route|
22
+ route[:engine] == engine_name
23
+ end
20
24
  end
21
25
 
22
26
  context 'all an engine\'s routes are internal' do
@@ -27,13 +31,19 @@ module Passages
27
31
  end
28
32
 
29
33
  context 'only some of an engine\'s routes are internal' do
30
- let(:another_fake_route) { instance_double(EngineRoute, internal?: false) }
31
- let(:routes) { [fake_route, another_fake_route]}
32
- subject { described_class.new([{engine: engine_name, routes: routes }]) }
34
+ subject do
35
+ described_class.new([{ engine: engine_name, routes: routes }])
36
+ end
37
+ let(:another_fake_route) do
38
+ instance_double(EngineRoute, internal?: false)
39
+ end
40
+ let(:routes) { [fake_route, another_fake_route] }
33
41
 
34
42
  it 'adds the engine to the ivar' do
35
43
  expect(subject.routes).to_not be_empty
36
- expect(subject.routes.all? { |r| r[:engine] == engine_name }).to eq(true)
44
+ expect(subject.routes).to be_all do |r|
45
+ r[:engine] == engine_name
46
+ end
37
47
  expect(subject.routes.first[:routes]).to eq(routes)
38
48
  end
39
49
  end
@@ -19,8 +19,8 @@ module Passages
19
19
  end
20
20
 
21
21
  [:internal?, :path].each do |method|
22
- describe "##{ method }" do
23
- it "responds to #{ method }" do
22
+ describe "##{method}" do
23
+ it "responds to #{method}" do
24
24
  expect(subject).to respond_to(method)
25
25
  end
26
26
  end
@@ -6,7 +6,9 @@ module Passages
6
6
  let(:fake_route) { instance_double(Passages::Route) }
7
7
 
8
8
  before do
9
- allow_any_instance_of(described_class).to receive(:main_app_name) { 'SomeGreatApp' }
9
+ allow_any_instance_of(described_class).to receive(:main_app_name) do
10
+ 'SomeGreatApp'
11
+ end
10
12
  allow(fake_route).to receive(:internal?) { false }
11
13
  end
12
14
 
@@ -34,7 +36,7 @@ module Passages
34
36
 
35
37
  context 'internal and external routes exist' do
36
38
  let(:another_fake_route) { instance_double(Passages::Route) }
37
- subject { described_class.new([fake_route, another_fake_route])}
39
+ subject { described_class.new([fake_route, another_fake_route]) }
38
40
 
39
41
  before do
40
42
  allow(another_fake_route).to receive(:internal?) { false }
@@ -42,7 +42,9 @@ module Passages
42
42
 
43
43
  describe '.from_raw_route' do
44
44
  let(:raw_route) { anything }
45
- before { allow(described_class).to receive(:mount_route_class) { mount_class } }
45
+ before do
46
+ allow(described_class).to receive(:mount_route_class) { mount_class }
47
+ end
46
48
 
47
49
  context 'mount class is present' do
48
50
  let(:mount_class) { anything }
data/version.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  module Passages
2
2
  MAJOR = 1
3
3
  MINOR = 4
4
- TINY = 0
4
+ TINY = 1
5
5
 
6
6
  VERSION = [MAJOR, MINOR, TINY].join('.').freeze
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: passages
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 1.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jake Yesbeck
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-24 00:00:00.000000000 Z
11
+ date: 2016-03-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -38,9 +38,25 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '3.2'
41
- description: Rails Engine to make internal routes searchable and discoverable for
42
- more than just the name of the route. All aspects of a route are searchable from
43
- the HTTP verb to the paramters a route supports.
41
+ - !ruby/object:Gem::Dependency
42
+ name: rubocop
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '='
46
+ - !ruby/object:Gem::Version
47
+ version: 0.39.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.39.0
55
+ description: |-
56
+ Rails Engine to make internal routes searchable and
57
+ discoverable for more than just the name of the route.
58
+ All aspects of a route are searchable from the HTTP
59
+ verb to the paramters a route supports.
44
60
  email: yesbeckjs@gmail.com
45
61
  executables: []
46
62
  extensions: []