rails_stuff 0.5.0 → 0.5.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0a6bd04d2e9f8e71c29e7b70748e3f1529715e0c
4
- data.tar.gz: fa5c7003161e787b1886de2b3c6e10955c812728
3
+ metadata.gz: 16d70694f5a696a150e54aad75558c05441d0c1c
4
+ data.tar.gz: b12c95387e4bd5593842d8ad4ba3db9d5dc9ad9f
5
5
  SHA512:
6
- metadata.gz: fa5e2a577b9de17bab80c9caf6e6e323d9637969f135e701042745271c9b60422d627a27c07311355feae66c2d29d4918ae498f5db542db1c0a50713a7c09c90
7
- data.tar.gz: a70871bf1a0814cd0551a6ad8a7f596b0912751925c04a5353920fdafcd55234344d7e8bb8a0e90c467455fcd3223cf0e3060b0d3c45bd0e21fc57be72d2632d
6
+ metadata.gz: e179c0f340c95ff4186022d6ab09053d023ae01cee10a0a276e697e02d387d3624626cf0c93b0bd43ee3e305330d747259e4d4a558af5c912cd9a8d336f207bc
7
+ data.tar.gz: e7e396a2265bb05e1312eaff05d5230788a77a2fc92780b4f8c099f9a40979f502975c2c6b2967fd91b41d2635527cd6ee943fbde73c8541ebb7c4a9537540b4
data/.gitignore CHANGED
@@ -1,6 +1,7 @@
1
1
  /.bundle/
2
2
  /.yardoc
3
3
  /Gemfile.lock
4
+ /gemfiles/*.lock
4
5
  /_yardoc/
5
6
  /coverage/
6
7
  /doc/
data/.travis.yml CHANGED
@@ -2,6 +2,9 @@ language: ruby
2
2
  cache: bundler
3
3
  rvm:
4
4
  - 2.2.3
5
+ gemfile:
6
+ - gemfiles/rails_4.gemfile
7
+ - gemfiles/rails_5.gemfile
5
8
  services:
6
9
  - redis
7
10
  notifications:
data/Appraisals ADDED
@@ -0,0 +1,12 @@
1
+ appraise 'rails-4' do
2
+ group :development do
3
+ gem 'rails', '~> 4.0'
4
+ end
5
+ end
6
+
7
+ appraise 'rails-5' do
8
+ group :development do
9
+ gem 'rails', '~> 5.0'
10
+ gem 'rails-controller-testing', '~> 0.1.1'
11
+ end
12
+ end
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  ## Unreleased
2
2
 
3
+ ## 0.5.1
4
+
5
+ Rails 5 support.
6
+
7
+ ## 0.5.0
8
+
3
9
  ### Controllers
4
10
 
5
11
  - `belongs_to`.
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.6.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.3.0'
18
- gem 'rspec-its', '~> 1.1.0'
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
@@ -3,6 +3,7 @@ set -euo pipefail
3
3
  IFS=$'\n\t'
4
4
 
5
5
  bundle install
6
+ appraisal install
6
7
  bin/install_git_hooks
7
8
 
8
9
  # Do any other automated setup that you need to do here
@@ -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 ||= ActiveRecord::Type::Boolean.new
107
- @boolean_parser.type_cast_from_user(val)
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
- model.singleton_class.send(:define_method, name) do |*args|
167
- all.scoping { instance_exec(*args, &body) } || all
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
 
@@ -6,7 +6,7 @@ module RailsStuff
6
6
  module VERSION #:nodoc:
7
7
  MAJOR = 0
8
8
  MINOR = 5
9
- TINY = 0
9
+ TINY = 1
10
10
  PRE = nil
11
11
 
12
12
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
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 'rails', '~> 4.0'
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.0
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-24 00:00:00.000000000 Z
11
+ date: 2016-10-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: rails
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