check_path 0.1.0

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: bf505f3a33872bc643317776b86ddc4ab15b4487
4
+ data.tar.gz: b6c4d83cd49601483bdd6754832682b528d9611d
5
+ SHA512:
6
+ metadata.gz: 969b19e12314056ed1ade1891fab4cbe0da3f49f87a5ce6f07b8b8d0675438015857e67b5e6895f588384a20a7f1ea25f0b770312e236054c5838b5671f945f6
7
+ data.tar.gz: 1d1ca1afffb285b5719d8ee1a385add1fc490c1887817b978dcedaf5d4159a8140f5061d2fced662748b13c8e63ccbc5b748947d35ec47351e2592834e780e27
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2015 kami
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,72 @@
1
+ # CheckPath
2
+
3
+ [![Build Status](https://travis-ci.org/kami30k/check_path.svg)](https://travis-ci.org/kami30k/check_path)
4
+ [![Gem Version](https://badge.fury.io/rb/check_path.svg)](http://badge.fury.io/rb/check_path)
5
+
6
+ CheckPath extends ActionView::Helpers::UrlHelper in Rails application.
7
+ It just add some methods, such as `root_path?`, `post_path?(id: 1)`, and so on.
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'check_path'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ ```
20
+ $ bundle
21
+ ```
22
+
23
+ ## Usage
24
+
25
+ When you add to `Gemfile` and run `bundle install`, you can use some methods in view files.
26
+
27
+ If your `config/routes.rb` is follows:
28
+
29
+ ```ruby
30
+ Rails.application.routes.draw do
31
+ resources :posts, only: [:index, :new, :edit, :show]
32
+
33
+ root 'posts#index'
34
+ end
35
+ ```
36
+
37
+ Then following methods are available in your view files:
38
+
39
+ - `root_path?`
40
+ - `posts_path?`
41
+ - `new_post_path?`
42
+ - `edit_post_path?(:id)`
43
+ - `post_path?(:id)`
44
+
45
+ For example, you can check current page is `new_post_path` or not in `app/views/layouts/application.html.erb`:
46
+
47
+ ```erb
48
+ <% if new_post_path? %>
49
+ <!-- Show only in new_post_path -->
50
+ <% end %>
51
+ ```
52
+
53
+ ## Background
54
+
55
+ As you know, the logic of these methods are as follows.
56
+ So you might this gem is not required.
57
+
58
+ ```ruby
59
+ def root_path?
60
+ current_page?(root_path)
61
+ end
62
+ ```
63
+
64
+ However, using this gem, your code will more clearly.
65
+
66
+ ## Contributing
67
+
68
+ 1. Fork it ( https://github.com/kami30k/check_path/fork )
69
+ 2. Create your feature branch (git checkout -b my-new-feature)
70
+ 3. Commit your changes (git commit -am 'Add some feature')
71
+ 4. Push to the branch (git push origin my-new-feature)
72
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,21 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'RailsCheckPath'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ require 'rspec/core/rake_task'
18
+ RSpec::Core::RakeTask.new(:spec)
19
+ task default: :spec
20
+
21
+ Bundler::GemHelper.install_tasks
data/lib/check_path.rb ADDED
@@ -0,0 +1,3 @@
1
+ require 'check_path/version'
2
+ require 'check_path/base'
3
+ require 'check_path/railtie'
@@ -0,0 +1,26 @@
1
+ module CheckPath
2
+ module Base
3
+ class << self
4
+ def included(klass)
5
+ _session = session
6
+
7
+ paths.each do |path|
8
+ define_method "#{path}?" do |args = nil|
9
+ current_page?(_session.send(path, args))
10
+ end
11
+ end
12
+ end
13
+
14
+ private
15
+
16
+ def paths
17
+ paths = session.methods.select { |method| method.to_s.include?('_path') }
18
+ paths.map(&:to_s)
19
+ end
20
+
21
+ def session
22
+ ActionDispatch::Integration::Session.new(Rails.application)
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,9 @@
1
+ module CheckPath
2
+ class Railtie < ::Rails::Railtie
3
+ initializer 'check_path' do
4
+ ActiveSupport.on_load(:action_controller) do
5
+ ActionView::Base.send :include, CheckPath::Base
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ module CheckPath
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: check_path
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - kami
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-01-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 4.2.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 4.2.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: sqlite3
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec-rails
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
+ description: Add some helpers that checks current path.
56
+ email:
57
+ - kami30k@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - MIT-LICENSE
63
+ - README.md
64
+ - Rakefile
65
+ - lib/check_path.rb
66
+ - lib/check_path/base.rb
67
+ - lib/check_path/railtie.rb
68
+ - lib/check_path/version.rb
69
+ homepage: https://github.com/kami30k/check_path
70
+ licenses:
71
+ - MIT
72
+ metadata: {}
73
+ post_install_message:
74
+ rdoc_options: []
75
+ require_paths:
76
+ - lib
77
+ required_ruby_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ required_rubygems_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ requirements: []
88
+ rubyforge_project:
89
+ rubygems_version: 2.2.2
90
+ signing_key:
91
+ specification_version: 4
92
+ summary: Add some helpers that checks current path.
93
+ test_files: []