Skip to content

Commit 07b4225

Browse files
author
Ivan Denysov
authored
Merge branch 'master' into use_current_module_namespace_for_decorates_association
2 parents e6a75b6 + 9cb42f6 commit 07b4225

28 files changed

+299
-55
lines changed

.github/workflows/ci.yml

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
---
2+
name: CI
3+
4+
on:
5+
- push
6+
- pull_request
7+
8+
jobs:
9+
rspec:
10+
runs-on: ubuntu-20.04
11+
strategy:
12+
fail-fast: false
13+
matrix:
14+
ruby:
15+
- '3.0'
16+
- '2.7'
17+
- '2.6'
18+
- '2.5'
19+
- '2.4'
20+
21+
services:
22+
mongodb:
23+
image: mongo
24+
ports:
25+
- 27017:27017
26+
27+
steps:
28+
- name: Checkout
29+
uses: actions/checkout@v2
30+
31+
- name: Setup Ruby
32+
uses: ruby/setup-ruby@v1
33+
with:
34+
ruby-version: ${{ matrix.ruby }}
35+
36+
- name: Setup Ruby cache
37+
uses: actions/cache@v2
38+
with:
39+
path: vendor/bundle
40+
key: ${{ runner.os }}-gems-${{ matrix.ruby }}-${{ hashFiles('**/Gemfile.lock') }}
41+
restore-keys: |
42+
${{ runner.os }}-gems-${{ matrix.ruby }}-
43+
44+
- name: Bundle
45+
run: |
46+
gem install bundler
47+
bundle config path vendor/bundle
48+
bundle install --jobs 4 --retry 3
49+
50+
- name: RSpec & publish code coverage
51+
uses: paambaati/[email protected]
52+
env:
53+
CC_TEST_REPORTER_ID: b7ba588af2a540fa96c267b3655a2afe31ea29976dc25905a668dd28d5e88915
54+
with:
55+
coverageCommand: bin/rake

.travis.yml

-29
This file was deleted.

CHANGELOG.md

+25
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,30 @@
11
# Draper Changelog
22

3+
## 4.0.1 - 2020-03-25
4+
5+
### Fixes
6+
* Check only object's private methods when preventing delegation [#875](https://github.com/drapergem/draper/pull/875)
7+
8+
### Other Changes
9+
* Use `alias` over `alias_method` [#877](https://github.com/drapergem/draper/pull/877)
10+
11+
## 4.0.0 - 2020-02-05
12+
13+
### Breaking Changes
14+
* Drop support for Ruby < 2.4 [#852](https://github.com/drapergem/draper/pull/852), [#872](https://github.com/drapergem/draper/pull/872)
15+
* Don't delegate public methods overridden by a private method in the decorator [#849](https://github.com/drapergem/draper/pull/849)
16+
17+
### Fixes
18+
* Add preservation of decorator options on QueryMethods [#868](https://github.com/drapergem/draper/pull/868)
19+
* Add `#respond_to_missing?` to `CollectionDecorator` so it correctly responds to ORM methods [#850](https://github.com/drapergem/draper/pull/850)
20+
* Fix deprecation warning with the new Rails 6 `ActionView::Base` constructor [#866](https://github.com/drapergem/draper/pull/866)
21+
* Fix deprecation warning with Ruby 2.7 [#870](https://github.com/drapergem/draper/pull/870)
22+
23+
### Other Changes
24+
* Add SimpleCov for code coverage analysis [#851](https://github.com/drapergem/draper/pull/851)
25+
* Update RSpec syntax in the README [#855](https://github.com/drapergem/draper/pull/855)
26+
* Update continuous integration configuration [#861](https://github.com/drapergem/draper/pull/861), [#862](https://github.com/drapergem/draper/pull/862), [#863](https://github.com/drapergem/draper/pull/863), [#872](https://github.com/drapergem/draper/pull/872)
27+
328
## 3.1.0
429
* Rails 6 support [#841](https://github.com/drapergem/draper/pull/841)
530
* Include ORM query methods in `CollectionDecorator` (e.g. `includes`) [#845](https://github.com/drapergem/draper/pull/845)

Gemfile

+11-2
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,22 @@ source "https://rubygems.org"
33
gemspec
44

55
platforms :ruby do
6-
gem 'sqlite3', '~> 1.3.6'
6+
if RUBY_VERSION >= "2.5.0"
7+
gem 'sqlite3'
8+
else
9+
gem 'sqlite3', '~> 1.3.6'
10+
end
711
end
812

913
platforms :jruby do
1014
gem "minitest"
1115
gem "activerecord-jdbcsqlite3-adapter"
1216
end
1317

14-
gem "rails", "~> 5.0"
18+
if RUBY_VERSION >= "2.5.0"
19+
gem "rails", "~> 6.0"
20+
gem 'webrick'
21+
else
22+
gem "rails", "~> 5.0"
23+
end
1524
gem "mongoid", github: "mongodb/mongoid"

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ Decorators are the ideal place to:
108108

109109
## Installation
110110

111-
As of version 3.0.0, Draper is only compatible with Rails 5 / Ruby 2.2 and later. Add Draper to your Gemfile.
111+
As of version 4.0.0, Draper only officially supports Rails 5.2 / Ruby 2.4 and later. Add Draper to your Gemfile.
112112

113113
```ruby
114114
gem 'draper'

bin/bundle

+114
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
#!/usr/bin/env ruby
2+
# frozen_string_literal: true
3+
4+
#
5+
# This file was generated by Bundler.
6+
#
7+
# The application 'bundle' is installed as part of a gem, and
8+
# this file is here to facilitate running it.
9+
#
10+
11+
require "rubygems"
12+
13+
m = Module.new do
14+
module_function
15+
16+
def invoked_as_script?
17+
File.expand_path($0) == File.expand_path(__FILE__)
18+
end
19+
20+
def env_var_version
21+
ENV["BUNDLER_VERSION"]
22+
end
23+
24+
def cli_arg_version
25+
return unless invoked_as_script? # don't want to hijack other binstubs
26+
return unless "update".start_with?(ARGV.first || " ") # must be running `bundle update`
27+
bundler_version = nil
28+
update_index = nil
29+
ARGV.each_with_index do |a, i|
30+
if update_index && update_index.succ == i && a =~ Gem::Version::ANCHORED_VERSION_PATTERN
31+
bundler_version = a
32+
end
33+
next unless a =~ /\A--bundler(?:[= ](#{Gem::Version::VERSION_PATTERN}))?\z/
34+
bundler_version = $1
35+
update_index = i
36+
end
37+
bundler_version
38+
end
39+
40+
def gemfile
41+
gemfile = ENV["BUNDLE_GEMFILE"]
42+
return gemfile if gemfile && !gemfile.empty?
43+
44+
File.expand_path("../../Gemfile", __FILE__)
45+
end
46+
47+
def lockfile
48+
lockfile =
49+
case File.basename(gemfile)
50+
when "gems.rb" then gemfile.sub(/\.rb$/, gemfile)
51+
else "#{gemfile}.lock"
52+
end
53+
File.expand_path(lockfile)
54+
end
55+
56+
def lockfile_version
57+
return unless File.file?(lockfile)
58+
lockfile_contents = File.read(lockfile)
59+
return unless lockfile_contents =~ /\n\nBUNDLED WITH\n\s{2,}(#{Gem::Version::VERSION_PATTERN})\n/
60+
Regexp.last_match(1)
61+
end
62+
63+
def bundler_version
64+
@bundler_version ||=
65+
env_var_version || cli_arg_version ||
66+
lockfile_version
67+
end
68+
69+
def bundler_requirement
70+
return "#{Gem::Requirement.default}.a" unless bundler_version
71+
72+
bundler_gem_version = Gem::Version.new(bundler_version)
73+
74+
requirement = bundler_gem_version.approximate_recommendation
75+
76+
return requirement unless Gem::Version.new(Gem::VERSION) < Gem::Version.new("2.7.0")
77+
78+
requirement += ".a" if bundler_gem_version.prerelease?
79+
80+
requirement
81+
end
82+
83+
def load_bundler!
84+
ENV["BUNDLE_GEMFILE"] ||= gemfile
85+
86+
activate_bundler
87+
end
88+
89+
def activate_bundler
90+
gem_error = activation_error_handling do
91+
gem "bundler", bundler_requirement
92+
end
93+
return if gem_error.nil?
94+
require_error = activation_error_handling do
95+
require "bundler/version"
96+
end
97+
return if require_error.nil? && Gem::Requirement.new(bundler_requirement).satisfied_by?(Gem::Version.new(Bundler::VERSION))
98+
warn "Activating bundler (#{bundler_requirement}) failed:\n#{gem_error.message}\n\nTo install the version of bundler this project requires, run `gem install bundler -v '#{bundler_requirement}'`"
99+
exit 42
100+
end
101+
102+
def activation_error_handling
103+
yield
104+
nil
105+
rescue StandardError, LoadError => e
106+
e
107+
end
108+
end
109+
110+
m.load_bundler!
111+
112+
if m.invoked_as_script?
113+
load Gem.bin_path("bundler", "bundle")
114+
end

bin/rake

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env ruby
2+
# frozen_string_literal: true
3+
4+
#
5+
# This file was generated by Bundler.
6+
#
7+
# The application 'rake' is installed as part of a gem, and
8+
# this file is here to facilitate running it.
9+
#
10+
11+
require "pathname"
12+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13+
Pathname.new(__FILE__).realpath)
14+
15+
bundle_binstub = File.expand_path("../bundle", __FILE__)
16+
17+
if File.file?(bundle_binstub)
18+
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19+
load(bundle_binstub)
20+
else
21+
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22+
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23+
end
24+
end
25+
26+
require "rubygems"
27+
require "bundler/setup"
28+
29+
load Gem.bin_path("rake", "rake")

draper.gemspec

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
require File.join(__dir__, "lib", "draper", "version")
1+
require_relative 'lib/draper/version'
22

33
Gem::Specification.new do |s|
44
s.name = "draper"
@@ -12,7 +12,6 @@ Gem::Specification.new do |s|
1212

1313
s.files = `git ls-files`.split("\n")
1414
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
15-
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
1615
s.require_paths = ["lib"]
1716

1817
s.required_ruby_version = '>= 2.2.2'
@@ -22,6 +21,7 @@ Gem::Specification.new do |s|
2221
s.add_dependency 'request_store', '>= 1.0'
2322
s.add_dependency 'activemodel', '>= 5.0'
2423
s.add_dependency 'activemodel-serializers-xml', '>= 1.0'
24+
s.add_dependency 'ruby2_keywords'
2525

2626
s.add_development_dependency 'ammeter'
2727
s.add_development_dependency 'rake'
@@ -30,5 +30,5 @@ Gem::Specification.new do |s|
3030
s.add_development_dependency 'capybara'
3131
s.add_development_dependency 'active_model_serializers', '>= 0.10'
3232
s.add_development_dependency 'rubocop'
33-
s.add_development_dependency 'simplecov'
33+
s.add_development_dependency 'simplecov', '0.17.1'
3434
end

lib/draper.rb

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
require 'active_support/core_ext/hash/reverse_merge'
99
require 'active_support/core_ext/name_error'
1010

11+
require 'ruby2_keywords'
12+
1113
require 'draper/version'
1214
require 'draper/configuration'
1315
require 'draper/view_helpers'

lib/draper/automatic_delegation.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ module AutomaticDelegation
66
# method calls to `object` as well. Calling `super` will first try to call the method on
77
# the parent decorator class. If no method exists on the parent class, it will then try
88
# to call the method on the `object`.
9-
def method_missing(method, *args, &block)
9+
ruby2_keywords def method_missing(method, *args, &block)
1010
return super unless delegatable?(method)
1111

1212
object.send(method, *args, &block)
@@ -20,14 +20,14 @@ def respond_to_missing?(method, include_private = false)
2020

2121
# @private
2222
def delegatable?(method)
23-
return if private_methods.include?(method)
23+
return if private_methods(false).include?(method)
2424

2525
object.respond_to?(method)
2626
end
2727

2828
module ClassMethods
2929
# Proxies missing class methods to the source class.
30-
def method_missing(method, *args, &block)
30+
ruby2_keywords def method_missing(method, *args, &block)
3131
return super unless delegatable?(method)
3232

3333
object_class.send(method, *args, &block)

lib/draper/compatibility/api_only.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ module ApiOnly
1414
extend ActiveSupport::Concern
1515

1616
included do
17-
alias_method :previous_render_to_body, :render_to_body
17+
alias :previous_render_to_body :render_to_body
1818
include ActionView::Rendering
19-
alias_method :render_to_body, :previous_render_to_body
19+
alias :render_to_body :previous_render_to_body
2020
end
2121
end
2222
end

lib/draper/delegation.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ module Delegation
77
# @return [void]
88
def delegate(*methods)
99
options = methods.extract_options!
10-
super *methods, options.reverse_merge(to: :object)
10+
super(*methods, **options.reverse_merge(to: :object))
1111
end
1212
end
1313
end

lib/draper/helper_proxy.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ def initialize(view_context)
88
end
99

1010
# Sends helper methods to the view context.
11-
def method_missing(method, *args, &block)
11+
ruby2_keywords def method_missing(method, *args, &block)
1212
self.class.define_proxy method
1313
send(method, *args, &block)
1414
end
@@ -31,6 +31,7 @@ def self.define_proxy(name)
3131
define_method name do |*args, &block|
3232
view_context.send(name, *args, &block)
3333
end
34+
ruby2_keywords name
3435
end
3536
end
3637
end

0 commit comments

Comments
 (0)