rails_stuff 0.5.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +3 -0
- data/Appraisals +12 -0
- data/CHANGELOG.md +6 -0
- data/Gemfile +6 -4
- data/README.md +3 -0
- data/bin/setup +1 -0
- data/gemfiles/rails_4.gemfile +24 -0
- data/gemfiles/rails_5.gemfile +25 -0
- data/lib/rails_stuff/params_parser.rb +12 -2
- data/lib/rails_stuff/sort_scope.rb +2 -1
- data/lib/rails_stuff/statusable.rb +7 -2
- data/lib/rails_stuff/version.rb +1 -1
- data/lib/rails_stuff.rb +11 -0
- data/rails_stuff.gemspec +1 -1
- metadata +14 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 16d70694f5a696a150e54aad75558c05441d0c1c
|
4
|
+
data.tar.gz: b12c95387e4bd5593842d8ad4ba3db9d5dc9ad9f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e179c0f340c95ff4186022d6ab09053d023ae01cee10a0a276e697e02d387d3624626cf0c93b0bd43ee3e305330d747259e4d4a558af5c912cd9a8d336f207bc
|
7
|
+
data.tar.gz: e7e396a2265bb05e1312eaff05d5230788a77a2fc92780b4f8c099f9a40979f502975c2c6b2967fd91b41d2635527cd6ee943fbde73c8541ebb7c4a9537540b4
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/Appraisals
ADDED
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
@@ -2,6 +2,9 @@ source 'https://rubygems.org'
|
|
2
2
|
gemspec
|
3
3
|
|
4
4
|
group :development do
|
5
|
+
gem 'rails'
|
6
|
+
gem 'appraisal', '~> 2.1.0'
|
7
|
+
|
5
8
|
gem 'sdoc', '~> 0.4.1'
|
6
9
|
gem 'pry', '~> 0.10.1'
|
7
10
|
gem 'pry-byebug', '~> 3.2.0'
|
@@ -10,13 +13,12 @@ group :development do
|
|
10
13
|
gem 'database_cleaner', '~> 1.5.0'
|
11
14
|
gem 'pooled_redis', '~> 0.2.1'
|
12
15
|
gem 'activemodel_translation', '~> 0.1.0'
|
13
|
-
gem 'has_scope', '~> 0.
|
16
|
+
gem 'has_scope', '~> 0.7.0'
|
14
17
|
gem 'responders', '~> 2.1.0'
|
15
18
|
gem 'kaminari', '~> 0.16.3'
|
16
19
|
|
17
|
-
gem 'rspec', '~> 3.
|
18
|
-
gem 'rspec-its', '~> 1.
|
19
|
-
gem 'rspec-rails', '~> 3.3.3'
|
20
|
+
gem 'rspec-rails', '~> 3.5.2'
|
21
|
+
gem 'rspec-its', '~> 1.2.0'
|
20
22
|
|
21
23
|
gem 'rubocop', '~> 0.37.2'
|
22
24
|
|
data/README.md
CHANGED
@@ -472,6 +472,9 @@ $('.selector').myPlugin().myPlugin('customAction')
|
|
472
472
|
After checking out the repo, run `bin/setup` to install dependencies.
|
473
473
|
Then, run `bin/console` for an interactive prompt that will allow you to experiment.
|
474
474
|
|
475
|
+
Use [appraisal](https://github.com/thoughtbot/appraisal) to run specs:
|
476
|
+
`appraisal rspec`.
|
477
|
+
|
475
478
|
To install this gem onto your local machine, run `bundle exec rake install`.
|
476
479
|
To release a new version, update the version number in `version.rb`,
|
477
480
|
and then run `bundle exec rake release` to create a git tag for the version,
|
data/bin/setup
CHANGED
@@ -0,0 +1,24 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
group :development do
|
6
|
+
gem "rails", "~> 4.0"
|
7
|
+
gem "appraisal", "~> 2.1.0"
|
8
|
+
gem "sdoc", "~> 0.4.1"
|
9
|
+
gem "pry", "~> 0.10.1"
|
10
|
+
gem "pry-byebug", "~> 3.2.0"
|
11
|
+
gem "sqlite3", "~> 1.3.10"
|
12
|
+
gem "database_cleaner", "~> 1.5.0"
|
13
|
+
gem "pooled_redis", "~> 0.2.1"
|
14
|
+
gem "activemodel_translation", "~> 0.1.0"
|
15
|
+
gem "has_scope", "~> 0.7.0"
|
16
|
+
gem "responders", "~> 2.1.0"
|
17
|
+
gem "kaminari", "~> 0.16.3"
|
18
|
+
gem "rspec-rails", "~> 3.5.2"
|
19
|
+
gem "rspec-its", "~> 1.2.0"
|
20
|
+
gem "rubocop", "~> 0.37.2"
|
21
|
+
gem "coveralls", "~> 0.8.2", :require => false
|
22
|
+
end
|
23
|
+
|
24
|
+
gemspec :path => "../"
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
group :development do
|
6
|
+
gem "rails", "~> 5.0"
|
7
|
+
gem "appraisal", "~> 2.1.0"
|
8
|
+
gem "sdoc", "~> 0.4.1"
|
9
|
+
gem "pry", "~> 0.10.1"
|
10
|
+
gem "pry-byebug", "~> 3.2.0"
|
11
|
+
gem "sqlite3", "~> 1.3.10"
|
12
|
+
gem "database_cleaner", "~> 1.5.0"
|
13
|
+
gem "pooled_redis", "~> 0.2.1"
|
14
|
+
gem "activemodel_translation", "~> 0.1.0"
|
15
|
+
gem "has_scope", "~> 0.7.0"
|
16
|
+
gem "responders", "~> 2.1.0"
|
17
|
+
gem "kaminari", "~> 0.16.3"
|
18
|
+
gem "rspec-rails", "~> 3.5.2"
|
19
|
+
gem "rspec-its", "~> 1.2.0"
|
20
|
+
gem "rubocop", "~> 0.37.2"
|
21
|
+
gem "coveralls", "~> 0.8.2", :require => false
|
22
|
+
gem "rails-controller-testing", "~> 0.1.1"
|
23
|
+
end
|
24
|
+
|
25
|
+
gemspec :path => "../"
|
@@ -103,8 +103,18 @@ module RailsStuff
|
|
103
103
|
# Parse boolean using ActiveResord's parser.
|
104
104
|
def parse_boolean(val)
|
105
105
|
parse(val) do
|
106
|
-
@boolean_parser ||=
|
107
|
-
@boolean_parser
|
106
|
+
@boolean_parser ||= boolean_parser
|
107
|
+
@boolean_parser[val]
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
def boolean_parser
|
112
|
+
require 'active_record'
|
113
|
+
ar_parser = ActiveRecord::Type::Boolean.new
|
114
|
+
if RailsStuff.rails4?
|
115
|
+
->(val) { ar_parser.type_cast_from_user(val) }
|
116
|
+
else
|
117
|
+
->(val) { ar_parser.cast(val) }
|
108
118
|
end
|
109
119
|
end
|
110
120
|
|
@@ -8,7 +8,7 @@ module RailsStuff
|
|
8
8
|
# to allowed subset.
|
9
9
|
module SortScope
|
10
10
|
# Register type for has_scop that accepts stings, hashes & arrays.
|
11
|
-
HasScope::ALLOWED_TYPES[:any] = [[String, Hash, Array, Symbol]]
|
11
|
+
HasScope::ALLOWED_TYPES[:any] = [[String, Hash, Array, Symbol, ActionController::Parameters]]
|
12
12
|
|
13
13
|
# Setups has_scope to order collection by allowed columns.
|
14
14
|
# Sort column is filtered by SortScope.filter_param method.
|
@@ -54,6 +54,7 @@ module RailsStuff
|
|
54
54
|
def filter_param(val, params, allowed, default = nil)
|
55
55
|
val ||= default
|
56
56
|
unless val == default
|
57
|
+
val = val.to_unsafe_h if val.is_a?(ActionController::Parameters)
|
57
58
|
val =
|
58
59
|
if val.is_a?(Hash)
|
59
60
|
val.each_with_object({}) do |(key, dir), h|
|
@@ -162,9 +162,14 @@ module RailsStuff
|
|
162
162
|
end
|
163
163
|
|
164
164
|
# Rails 4 doesn't use `instance_exec` for scopes, so we do it manually.
|
165
|
+
# For Rails 5 it's just use `.scope`.
|
165
166
|
def define_scope(name, body)
|
166
|
-
|
167
|
-
|
167
|
+
if RailsStuff.rails4?
|
168
|
+
model.singleton_class.send(:define_method, name) do |*args|
|
169
|
+
all.scoping { instance_exec(*args, &body) } || all
|
170
|
+
end
|
171
|
+
else
|
172
|
+
model.scope(name, body)
|
168
173
|
end
|
169
174
|
end
|
170
175
|
|
data/lib/rails_stuff/version.rb
CHANGED
data/lib/rails_stuff.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'rails_stuff/version'
|
2
|
+
require 'active_support/version'
|
2
3
|
require 'active_support/dependencies/autoload'
|
3
4
|
|
4
5
|
# Useful stuff for Rails.
|
@@ -16,6 +17,16 @@ module RailsStuff
|
|
16
17
|
autoload :SortScope
|
17
18
|
autoload :Statusable
|
18
19
|
autoload :TypesTracker
|
20
|
+
|
21
|
+
module_function
|
22
|
+
|
23
|
+
def rails_version
|
24
|
+
@rails_version = ActiveSupport::VERSION
|
25
|
+
end
|
26
|
+
|
27
|
+
def rails4?
|
28
|
+
rails_version::MAJOR == 4
|
29
|
+
end
|
19
30
|
end
|
20
31
|
|
21
32
|
require 'rails_stuff/engine' if defined?(Rails::Engine)
|
data/rails_stuff.gemspec
CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
19
|
spec.require_paths = ['lib']
|
20
20
|
|
21
|
-
spec.add_dependency '
|
21
|
+
spec.add_dependency 'activesupport', '> 4.0', '< 6.0'
|
22
22
|
|
23
23
|
spec.add_development_dependency 'bundler', '~> 1.8'
|
24
24
|
spec.add_development_dependency 'rake', '~> 10.0'
|
metadata
CHANGED
@@ -1,29 +1,35 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_stuff
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Max Melentiev
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-10-
|
11
|
+
date: 2016-10-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: activesupport
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '4.0'
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '6.0'
|
20
23
|
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
23
26
|
requirements:
|
24
|
-
- - "
|
27
|
+
- - ">"
|
25
28
|
- !ruby/object:Gem::Version
|
26
29
|
version: '4.0'
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '6.0'
|
27
33
|
- !ruby/object:Gem::Dependency
|
28
34
|
name: bundler
|
29
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -63,6 +69,7 @@ files:
|
|
63
69
|
- ".rspec"
|
64
70
|
- ".rubocop.yml"
|
65
71
|
- ".travis.yml"
|
72
|
+
- Appraisals
|
66
73
|
- CHANGELOG.md
|
67
74
|
- Gemfile
|
68
75
|
- LICENSE.txt
|
@@ -72,6 +79,8 @@ files:
|
|
72
79
|
- bin/git-hooks/pre-commit
|
73
80
|
- bin/install_git_hooks
|
74
81
|
- bin/setup
|
82
|
+
- gemfiles/rails_4.gemfile
|
83
|
+
- gemfiles/rails_5.gemfile
|
75
84
|
- lib/assets/javascripts/rails_stuff/plugin_manager.coffee
|
76
85
|
- lib/assets/stylesheets/rails_stuff/_media_queries.scss
|
77
86
|
- lib/net/http/debug.rb
|