Skip to content

Commit

Permalink
Merge branch 'master' into use_current_module_namespace_for_decorates…
Browse files Browse the repository at this point in the history
…_association
  • Loading branch information
Ivan Denysov authored Feb 19, 2021
2 parents e6a75b6 + 9cb42f6 commit 07b4225
Show file tree
Hide file tree
Showing 28 changed files with 299 additions and 55 deletions.
55 changes: 55 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
---
name: CI

on:
- push
- pull_request

jobs:
rspec:
runs-on: ubuntu-20.04
strategy:
fail-fast: false
matrix:
ruby:
- '3.0'
- '2.7'
- '2.6'
- '2.5'
- '2.4'

services:
mongodb:
image: mongo
ports:
- 27017:27017

steps:
- name: Checkout
uses: actions/checkout@v2

- name: Setup Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}

- name: Setup Ruby cache
uses: actions/cache@v2
with:
path: vendor/bundle
key: ${{ runner.os }}-gems-${{ matrix.ruby }}-${{ hashFiles('**/Gemfile.lock') }}
restore-keys: |
${{ runner.os }}-gems-${{ matrix.ruby }}-
- name: Bundle
run: |
gem install bundler
bundle config path vendor/bundle
bundle install --jobs 4 --retry 3
- name: RSpec & publish code coverage
uses: paambaati/[email protected]
env:
CC_TEST_REPORTER_ID: b7ba588af2a540fa96c267b3655a2afe31ea29976dc25905a668dd28d5e88915
with:
coverageCommand: bin/rake
29 changes: 0 additions & 29 deletions .travis.yml

This file was deleted.

25 changes: 25 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,30 @@
# Draper Changelog

## 4.0.1 - 2020-03-25

### Fixes
* Check only object's private methods when preventing delegation [#875](https://github.com/drapergem/draper/pull/875)

### Other Changes
* Use `alias` over `alias_method` [#877](https://github.com/drapergem/draper/pull/877)

## 4.0.0 - 2020-02-05

### Breaking Changes
* Drop support for Ruby < 2.4 [#852](https://github.com/drapergem/draper/pull/852), [#872](https://github.com/drapergem/draper/pull/872)
* Don't delegate public methods overridden by a private method in the decorator [#849](https://github.com/drapergem/draper/pull/849)

### Fixes
* Add preservation of decorator options on QueryMethods [#868](https://github.com/drapergem/draper/pull/868)
* Add `#respond_to_missing?` to `CollectionDecorator` so it correctly responds to ORM methods [#850](https://github.com/drapergem/draper/pull/850)
* Fix deprecation warning with the new Rails 6 `ActionView::Base` constructor [#866](https://github.com/drapergem/draper/pull/866)
* Fix deprecation warning with Ruby 2.7 [#870](https://github.com/drapergem/draper/pull/870)

### Other Changes
* Add SimpleCov for code coverage analysis [#851](https://github.com/drapergem/draper/pull/851)
* Update RSpec syntax in the README [#855](https://github.com/drapergem/draper/pull/855)
* 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)

## 3.1.0
* Rails 6 support [#841](https://github.com/drapergem/draper/pull/841)
* Include ORM query methods in `CollectionDecorator` (e.g. `includes`) [#845](https://github.com/drapergem/draper/pull/845)
Expand Down
13 changes: 11 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,22 @@ source "https://rubygems.org"
gemspec

platforms :ruby do
gem 'sqlite3', '~> 1.3.6'
if RUBY_VERSION >= "2.5.0"
gem 'sqlite3'
else
gem 'sqlite3', '~> 1.3.6'
end
end

platforms :jruby do
gem "minitest"
gem "activerecord-jdbcsqlite3-adapter"
end

gem "rails", "~> 5.0"
if RUBY_VERSION >= "2.5.0"
gem "rails", "~> 6.0"
gem 'webrick'
else
gem "rails", "~> 5.0"
end
gem "mongoid", github: "mongodb/mongoid"
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ Decorators are the ideal place to:

## Installation

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

```ruby
gem 'draper'
Expand Down
114 changes: 114 additions & 0 deletions bin/bundle
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

#
# This file was generated by Bundler.
#
# The application 'bundle' is installed as part of a gem, and
# this file is here to facilitate running it.
#

require "rubygems"

m = Module.new do
module_function

def invoked_as_script?
File.expand_path($0) == File.expand_path(__FILE__)
end

def env_var_version
ENV["BUNDLER_VERSION"]
end

def cli_arg_version
return unless invoked_as_script? # don't want to hijack other binstubs
return unless "update".start_with?(ARGV.first || " ") # must be running `bundle update`
bundler_version = nil
update_index = nil
ARGV.each_with_index do |a, i|
if update_index && update_index.succ == i && a =~ Gem::Version::ANCHORED_VERSION_PATTERN
bundler_version = a
end
next unless a =~ /\A--bundler(?:[= ](#{Gem::Version::VERSION_PATTERN}))?\z/
bundler_version = $1
update_index = i
end
bundler_version
end

def gemfile
gemfile = ENV["BUNDLE_GEMFILE"]
return gemfile if gemfile && !gemfile.empty?

File.expand_path("../../Gemfile", __FILE__)
end

def lockfile
lockfile =
case File.basename(gemfile)
when "gems.rb" then gemfile.sub(/\.rb$/, gemfile)
else "#{gemfile}.lock"
end
File.expand_path(lockfile)
end

def lockfile_version
return unless File.file?(lockfile)
lockfile_contents = File.read(lockfile)
return unless lockfile_contents =~ /\n\nBUNDLED WITH\n\s{2,}(#{Gem::Version::VERSION_PATTERN})\n/
Regexp.last_match(1)
end

def bundler_version
@bundler_version ||=
env_var_version || cli_arg_version ||
lockfile_version
end

def bundler_requirement
return "#{Gem::Requirement.default}.a" unless bundler_version

bundler_gem_version = Gem::Version.new(bundler_version)

requirement = bundler_gem_version.approximate_recommendation

return requirement unless Gem::Version.new(Gem::VERSION) < Gem::Version.new("2.7.0")

requirement += ".a" if bundler_gem_version.prerelease?

requirement
end

def load_bundler!
ENV["BUNDLE_GEMFILE"] ||= gemfile

activate_bundler
end

def activate_bundler
gem_error = activation_error_handling do
gem "bundler", bundler_requirement
end
return if gem_error.nil?
require_error = activation_error_handling do
require "bundler/version"
end
return if require_error.nil? && Gem::Requirement.new(bundler_requirement).satisfied_by?(Gem::Version.new(Bundler::VERSION))
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}'`"
exit 42
end

def activation_error_handling
yield
nil
rescue StandardError, LoadError => e
e
end
end

m.load_bundler!

if m.invoked_as_script?
load Gem.bin_path("bundler", "bundle")
end
29 changes: 29 additions & 0 deletions bin/rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

#
# This file was generated by Bundler.
#
# The application 'rake' is installed as part of a gem, and
# this file is here to facilitate running it.
#

require "pathname"
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
Pathname.new(__FILE__).realpath)

bundle_binstub = File.expand_path("../bundle", __FILE__)

if File.file?(bundle_binstub)
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
load(bundle_binstub)
else
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
end
end

require "rubygems"
require "bundler/setup"

load Gem.bin_path("rake", "rake")
6 changes: 3 additions & 3 deletions draper.gemspec
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require File.join(__dir__, "lib", "draper", "version")
require_relative 'lib/draper/version'

Gem::Specification.new do |s|
s.name = "draper"
Expand All @@ -12,7 +12,6 @@ Gem::Specification.new do |s|

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

s.required_ruby_version = '>= 2.2.2'
Expand All @@ -22,6 +21,7 @@ Gem::Specification.new do |s|
s.add_dependency 'request_store', '>= 1.0'
s.add_dependency 'activemodel', '>= 5.0'
s.add_dependency 'activemodel-serializers-xml', '>= 1.0'
s.add_dependency 'ruby2_keywords'

s.add_development_dependency 'ammeter'
s.add_development_dependency 'rake'
Expand All @@ -30,5 +30,5 @@ Gem::Specification.new do |s|
s.add_development_dependency 'capybara'
s.add_development_dependency 'active_model_serializers', '>= 0.10'
s.add_development_dependency 'rubocop'
s.add_development_dependency 'simplecov'
s.add_development_dependency 'simplecov', '0.17.1'
end
2 changes: 2 additions & 0 deletions lib/draper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
require 'active_support/core_ext/hash/reverse_merge'
require 'active_support/core_ext/name_error'

require 'ruby2_keywords'

require 'draper/version'
require 'draper/configuration'
require 'draper/view_helpers'
Expand Down
6 changes: 3 additions & 3 deletions lib/draper/automatic_delegation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module AutomaticDelegation
# method calls to `object` as well. Calling `super` will first try to call the method on
# the parent decorator class. If no method exists on the parent class, it will then try
# to call the method on the `object`.
def method_missing(method, *args, &block)
ruby2_keywords def method_missing(method, *args, &block)
return super unless delegatable?(method)

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

# @private
def delegatable?(method)
return if private_methods.include?(method)
return if private_methods(false).include?(method)

object.respond_to?(method)
end

module ClassMethods
# Proxies missing class methods to the source class.
def method_missing(method, *args, &block)
ruby2_keywords def method_missing(method, *args, &block)
return super unless delegatable?(method)

object_class.send(method, *args, &block)
Expand Down
4 changes: 2 additions & 2 deletions lib/draper/compatibility/api_only.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ module ApiOnly
extend ActiveSupport::Concern

included do
alias_method :previous_render_to_body, :render_to_body
alias :previous_render_to_body :render_to_body
include ActionView::Rendering
alias_method :render_to_body, :previous_render_to_body
alias :render_to_body :previous_render_to_body
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/draper/delegation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module Delegation
# @return [void]
def delegate(*methods)
options = methods.extract_options!
super *methods, options.reverse_merge(to: :object)
super(*methods, **options.reverse_merge(to: :object))
end
end
end
3 changes: 2 additions & 1 deletion lib/draper/helper_proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def initialize(view_context)
end

# Sends helper methods to the view context.
def method_missing(method, *args, &block)
ruby2_keywords def method_missing(method, *args, &block)
self.class.define_proxy method
send(method, *args, &block)
end
Expand All @@ -31,6 +31,7 @@ def self.define_proxy(name)
define_method name do |*args, &block|
view_context.send(name, *args, &block)
end
ruby2_keywords name
end
end
end
Loading

0 comments on commit 07b4225

Please sign in to comment.