params_keeper_rails 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e3849671b65b09469406cf424369f6738686eb9a
4
+ data.tar.gz: 0cd0bf4977454d69558c1c3f4556ccbd99d9bf62
5
+ SHA512:
6
+ metadata.gz: a0450d4f2c493ec326d95fe97e641a9d8e9838252c44c3585badb4b4eaee3091523b7d5e240f258930626a9e920e50704bf904585406b00d772ae30759f9142c
7
+ data.tar.gz: 7d8833985dc7d95fc448ea23a1caec19489dd80cf4426fb452bd95644b523e4c535a53489631415309572c106ac432cc11f0b17ef903bbbf352dbab8cf1bb78b
data/.gitignore ADDED
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /.project
4
+ /Gemfile.lock
5
+ /gemfiles/.bundle
6
+ /gemfiles/vendor
7
+ /gemfiles/*gemfile.lock
8
+ /_yardoc/
9
+ /coverage/
10
+ /doc/
11
+ /log/
12
+ /pkg/
13
+ /spec/reports/
14
+ /tmp/
15
+ /vendor/
data/.rspec ADDED
@@ -0,0 +1,4 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
4
+ --require rails_helper
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.3.4
4
+ - 2.4.1
5
+ gemfile:
6
+ - gemfiles/rails50.gemfile
7
+ - gemfiles/rails51.gemfile
8
+ before_install: gem install bundler -v 1.15.3
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at kaneta@sitebridge.co.jp. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in params_keeper_rails.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Yoshikazu Kaneta
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,81 @@
1
+ # ParamsKeeperRails
2
+
3
+ A rails gem for keeping specific parameters through links.
4
+
5
+ ## Dependencies
6
+
7
+ * ruby 2.3+
8
+ * rails 5.0+
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ ```ruby
15
+ gem 'params_keeper_rails'
16
+ ```
17
+
18
+ And then execute:
19
+
20
+ $ bundle
21
+
22
+ ## Usage
23
+
24
+ Include modules in your controller and specify parameter keys you want to keep:
25
+
26
+ ```ruby
27
+ class ExamplesController < ApplicationController
28
+ include ParamsKeeper::Controller
29
+ keep_params :key1, :key2
30
+ ```
31
+
32
+ Parameters are kept if destination controller is same as current controller.
33
+ For example:
34
+
35
+ ```ruby
36
+ GET "/examples?key1=**&key2=**"
37
+
38
+ # hash argument
39
+ url_for(action: :show) #=> '/examples/:id?key1=**&key2=**'
40
+
41
+ # string and active model arguments don't keep parameters by defalut
42
+ url_for('/examples') #=> '/examples'
43
+ url_for(@example) #=> '/examples/:id'
44
+
45
+ # parameters are not kept if destination controller is different from current controller
46
+ url_for(controller: 'examples2', action: :index) #=> '/examples2'
47
+
48
+ # parameters are not kept if you set keep_params: false
49
+ url_for(action: :show, keep_params: false) #=> '/examples/:id'
50
+ ```
51
+
52
+ Specify class of url_for argument:
53
+
54
+ ```ruby
55
+ keep_params :key1, :key2, args: [:hash] # only hash argument like url_for(action: :show) keeps parameters
56
+ keep_params :key1, :key2, args: [:string] # only string argument like url_for('/examples') keeps parameters
57
+ keep_params :key1, :key2, args: [:model] # only model argument like url_for(@example) keeps parameters
58
+ ```
59
+
60
+ Keep parameters throught multiple controllers:
61
+
62
+ ```ruby
63
+ class ExamplesController < ApplicationController
64
+ include ParamsKeeper::Controller
65
+ keep_params :key1, :key2, to: %w(examples nested_examples)
66
+ end
67
+
68
+ class NestedExamplesController < ApplicationController
69
+ include ParamsKeeper::Controller
70
+ keep_params :key1, :key2, to: %w(examples nested_examples)
71
+ end
72
+ ```
73
+
74
+ ## Contributing
75
+
76
+ Bug reports and pull requests are welcome on GitHub at https://github.com/kanety/params_keeper_rails. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
77
+
78
+ ## License
79
+
80
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
81
+
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,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "params_keeper/controller"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem "rails", "~> 5.0.5"
4
+
5
+ # Specify your gem's dependencies in params_keeper_rails.gemspec
6
+ gemspec path: "../"
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem "rails", "~> 5.1.3"
4
+
5
+ # Specify your gem's dependencies in params_keeper_rails.gemspec
6
+ gemspec path: "../"
@@ -0,0 +1,64 @@
1
+ require 'params_keeper/helper'
2
+
3
+ module ParamsKeeper::Controller
4
+ extend ActiveSupport::Concern
5
+
6
+ included do
7
+ class_attribute :keep_params_keys, :keep_params_configs
8
+ helper ParamsKeeper::Helper
9
+ end
10
+
11
+ def url_for(options = nil)
12
+ return super if options.is_a?(Hash) && options.delete(:keep_params) == false
13
+
14
+ configs = self.class.keep_params_configs
15
+ keys = self.class.keep_params_keys
16
+ return super if keys.blank?
17
+
18
+ if configs.key?(:args)
19
+ args = Array(configs[:args])
20
+ return super if (options.is_a?(Hash) && !args.include?(:hash)) ||
21
+ (options.is_a?(String) && !args.include?(:string)) ||
22
+ (options.class.respond_to?(:model_name) && !args.include?(:model))
23
+ elsif !options.is_a?(Hash)
24
+ return super
25
+ end
26
+
27
+ if options.is_a?(Hash)
28
+ if keep_params?(options, configs)
29
+ super(ParamsKeeper::Helper.merge_params(options, params, keys))
30
+ else
31
+ super
32
+ end
33
+ else
34
+ url = super(options)
35
+ url_opts = begin
36
+ Rails.application.routes.recognize_path(url)
37
+ rescue ActionController::RoutingError
38
+ nil
39
+ end
40
+ if url_opts && keep_params?(url_opts, configs)
41
+ super(ParamsKeeper::Helper.merge_params(url_opts, params, keys))
42
+ else
43
+ url
44
+ end
45
+ end
46
+ end
47
+
48
+ def keep_params?(options, configs)
49
+ controller = options[:controller].to_s
50
+ if configs[:to]
51
+ target = [controller, controller_name, controller_path]
52
+ Array(configs[:to]).any? { |c| c.to_s.in?(target) }
53
+ else
54
+ controller.blank? || controller.in?([controller_name, controller_path])
55
+ end
56
+ end
57
+
58
+ class_methods do
59
+ def keep_params(*args)
60
+ self.keep_params_configs = args.last.is_a?(Hash) ? args.pop : {}
61
+ self.keep_params_keys = Array(args)
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,12 @@
1
+ module ParamsKeeper::Helper
2
+ def url_for(options = nil)
3
+ controller.url_for(options)
4
+ end
5
+
6
+ class << self
7
+ def merge_params(options, params, keep_params_keys)
8
+ keeps = params.to_unsafe_h.deep_symbolize_keys.slice(*keep_params_keys.to_a)
9
+ options.reverse_merge(keeps)
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,3 @@
1
+ module ParamsKeeper
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,3 @@
1
+ require 'active_support'
2
+ require 'params_keeper/version'
3
+ require 'params_keeper/controller'
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'params_keeper/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "params_keeper_rails"
8
+ spec.version = ParamsKeeper::VERSION
9
+ spec.authors = ["Yoshikazu Kaneta"]
10
+ spec.email = ["kaneta@sitebridge.co.jp"]
11
+
12
+ spec.summary = %q{keep specific parameters through links.}
13
+ spec.description = %q{A rails gem for keeping specific parameters through links.}
14
+ spec.homepage = "https://github.com/kanety/params_keeper_rails"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.required_ruby_version = '>= 2.3'
23
+
24
+ spec.add_runtime_dependency "rails", ">= 5.0"
25
+
26
+ spec.add_development_dependency "rake"
27
+ spec.add_development_dependency "rspec"
28
+ spec.add_development_dependency "rspec-rails"
29
+ spec.add_development_dependency "rails-controller-testing"
30
+ spec.add_development_dependency "simplecov"
31
+ end
metadata ADDED
@@ -0,0 +1,145 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: params_keeper_rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Yoshikazu Kaneta
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-09-04 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: '5.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '5.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
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
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-rails
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: rails-controller-testing
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
+ - !ruby/object:Gem::Dependency
84
+ name: simplecov
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: A rails gem for keeping specific parameters through links.
98
+ email:
99
+ - kaneta@sitebridge.co.jp
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".rspec"
106
+ - ".travis.yml"
107
+ - CODE_OF_CONDUCT.md
108
+ - Gemfile
109
+ - LICENSE.txt
110
+ - README.md
111
+ - Rakefile
112
+ - bin/console
113
+ - bin/setup
114
+ - gemfiles/rails50.gemfile
115
+ - gemfiles/rails51.gemfile
116
+ - lib/params_keeper/controller.rb
117
+ - lib/params_keeper/helper.rb
118
+ - lib/params_keeper/version.rb
119
+ - lib/params_keeper_rails.rb
120
+ - params_keeper_rails.gemspec
121
+ homepage: https://github.com/kanety/params_keeper_rails
122
+ licenses:
123
+ - MIT
124
+ metadata: {}
125
+ post_install_message:
126
+ rdoc_options: []
127
+ require_paths:
128
+ - lib
129
+ required_ruby_version: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ version: '2.3'
134
+ required_rubygems_version: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ requirements: []
140
+ rubyforge_project:
141
+ rubygems_version: 2.6.13
142
+ signing_key:
143
+ specification_version: 4
144
+ summary: keep specific parameters through links.
145
+ test_files: []