docile 1.3.1 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 11815257ca44981c34b07c7f17fe1c2e6ca599783bc14aec836493812ebecd7b
4
- data.tar.gz: f605e98ec83e48744601de31ea5809744b11227b89b3822c172c82c894498515
3
+ metadata.gz: f4c79b9041a97cfbf6ee0a6d93a9e98a30cc188918d0916ed6b1321f8ac9dca6
4
+ data.tar.gz: 772048f651fadb4277aaa0cb0b91b45e1b95be9f36b3654a9eb5db1a0bb143ea
5
5
  SHA512:
6
- metadata.gz: 2eabf55eeea7884e053664c3c1dfab240ae7c6f808318de6dcc27d3d01b330d7ffe4e5983c4eeb95291462048b1ebd37d72a60018bc90bda55b0c3d6a6a5c746
7
- data.tar.gz: 6bf630c901e53f09e3c7d6ee2f3c1c102dcfe45f8536b44cd619bc6bfcf0711b98a7fe0a415115dbd67d5f0fedb3bffd77fada17f1d11ec2d25ba36e72752003
6
+ metadata.gz: b4e3e7a9fcc953aed658c154dd6a4e43bc258e0895b6a5457f34a93dbcfd1d13808dc2a7d558b133515af695a9283f276d0f744dc57ed7caeae7394bb1ebe3c1
7
+ data.tar.gz: 218c14f2cf80913d370376415f6c650e6c8d8eebfe8405f4529e820d3b2a46bf656ce45ca22ccb36a4409fffb31f823cea49515e1e21ed5c1584d66e55a9a550
@@ -0,0 +1,15 @@
1
+ version: 2
2
+
3
+ updates:
4
+
5
+ # Maintain dependencies for GitHub Actions
6
+ - package-ecosystem: "github-actions"
7
+ directory: "/"
8
+ schedule:
9
+ interval: "daily"
10
+
11
+ # Maintain dependencies for Ruby's Bundler
12
+ - package-ecosystem: "bundler"
13
+ directory: "/"
14
+ schedule:
15
+ interval: "daily"
@@ -0,0 +1,31 @@
1
+ name: Main
2
+ on:
3
+ push:
4
+ branches:
5
+ - main
6
+ pull_request:
7
+ branches:
8
+ - main
9
+ jobs:
10
+ test:
11
+ name: 'CI Tests'
12
+ strategy:
13
+ fail-fast: false
14
+ matrix:
15
+ os: [ubuntu-latest]
16
+ # Due to https://github.com/actions/runner/issues/849, we have to use quotes for '3.0'
17
+ ruby: [jruby, truffleruby, 2.5, 2.6, 2.7, '3.0', head]
18
+ runs-on: ${{ matrix.os }}
19
+ steps:
20
+ - uses: actions/checkout@v2.3.4
21
+ - uses: ruby/setup-ruby@v1
22
+ with:
23
+ ruby-version: ${{ matrix.ruby }}
24
+ bundler-cache: true
25
+ - run: bundle exec rspec
26
+ - uses: codecov/codecov-action@v1.5.0
27
+ with:
28
+ name: ${{ matrix.ruby }}
29
+ file: ./coverage/coverage.xml
30
+ - run: bundle exec rubocop
31
+ if: matrix.ruby == '3.0'
data/.rubocop.yml ADDED
@@ -0,0 +1,2 @@
1
+ inherit_gem:
2
+ panolint: rubocop.yml
data/Gemfile CHANGED
@@ -1,12 +1,26 @@
1
- require File.expand_path("on_what", File.dirname(__FILE__))
1
+ # frozen_string_literal: true
2
+
2
3
  source "https://rubygems.org"
3
4
 
4
- # Travis-only dependencies go here
5
- if on_travis? && !on_1_8? && !on_rubinius?
6
- group :test do
7
- gem "codecov", ">= 0.0.9", :require => false
8
- end
5
+ # CI-only dependencies go here
6
+ if ENV["CI"] == "true" # rubocop:disable Style/IfUnlessModifier
7
+ gem "simplecov-cobertura", require: false, group: "test"
9
8
  end
10
9
 
11
10
  # Specify gem's dependencies in docile.gemspec
12
11
  gemspec
12
+
13
+ group :test do
14
+ gem "rspec", "~> 3.10"
15
+ gem "simplecov", require: false
16
+ end
17
+
18
+ # Excluded from CI except on latest MRI Ruby, to reduce compatibility burden
19
+ group :checks do
20
+ gem "panolint", github: "panorama-ed/panolint", branch: "main"
21
+ end
22
+
23
+ # Optional, only used locally to release to rubygems.org
24
+ group :release, optional: true do
25
+ gem "rake"
26
+ end
data/HISTORY.md CHANGED
@@ -1,8 +1,51 @@
1
1
  # HISTORY
2
2
 
3
- ## [Unreleased changes](http://github.com/ms-ati/docile/compare/v1.3.1...master)
4
-
5
- - ...
3
+ ## [Unreleased changes](http://github.com/ms-ati/docile/compare/v1.4.0...main)
4
+
5
+ ## [v1.4.0 (May 12, 2021)](http://github.com/ms-ati/docile/compare/v1.3.5...v1.4.0)
6
+
7
+ - Special thanks to Matt Schreiber (@tomeon):
8
+ - Short-circuit to calling #instance_exec directly on the DSL object (prior to
9
+ constructing a proxy object) when the DSL object and block context object are
10
+ identical (*Sorry it took over a year to review and merge this!*)
11
+ - Renamed default branch from master to main, see: https://github.com/github/renaming
12
+ - Temporarily removed YARD doc configuration, to replace after
13
+ migration to Github Actions
14
+ - Removed support for all EOL Rubies < 2.6
15
+ - Migrated CI from Travis to Github Actions
16
+ - Special thanks (again!) to Taichi Ishitani (@taichi-ishitani):
17
+ - Use more reliable codecov github action (via simplecov-cobertura)
18
+ rather than less reliable codecov gem
19
+ - Enable bundle caching in github action setup-ruby
20
+ - Added Rubocop, and configured it to run in CI
21
+ - Added Dependabot, and configured it to run daily
22
+ - Added SECURITY.md for vulnerability reporting policy
23
+
24
+ ## [v1.3.5 (Jan 13, 2021)](http://github.com/ms-ati/docile/compare/v1.3.4...v1.3.5)
25
+
26
+ - Special thanks to Jochen Seeber (@jochenseeber):
27
+ - Fix remaining delegation on Ruby 2.7 (PR #62)
28
+ - Remove support for Ruby 1.8.7 and REE, because they
29
+ [are no longer runnable on Travis CI](https://travis-ci.community/t/ruby-1-8-7-and-ree-builds-broken-by-ssl-certificate-failure/10866)
30
+ - Announce that continued support for any EOL Ruby versions (that is, versions
31
+ prior to Ruby 2.5 as of Jan 13 2021) will be decided on **Feb 1, 2021**
32
+ based on comments to [issue #58](https://github.com/ms-ati/docile/issues/58)
33
+
34
+ ## [v1.3.4 (Dec 22, 2020)](http://github.com/ms-ati/docile/compare/v1.3.3...v1.3.4)
35
+
36
+ - Special thanks to Benoit Daloze (@eregon):
37
+ - Fix delegation on Ruby 2.7 (issues #45 and #44, PR #52)
38
+
39
+ ## [v1.3.3 (Dec 18, 2020)](http://github.com/ms-ati/docile/compare/v1.3.2...v1.3.3)
40
+
41
+ - Special thanks (again!) to Taichi Ishitani (@taichi-ishitani):
42
+ - Fix keyword arg warnings on Ruby 2.7 (issue #44, PR #45)
43
+ - Filter Docile's source files from backtrace (issue #35, PR #36)
44
+
45
+ ## [v1.3.2 (Jun 12, 2019)](http://github.com/ms-ati/docile/compare/v1.3.1...v1.3.2)
46
+
47
+ - Special thanks (again!) to Taichi Ishitani (@taichi-ishitani):
48
+ - Fix for DSL object is replaced when #dsl_eval is nested (#33, PR #34)
6
49
 
7
50
  ## [v1.3.1 (May 24, 2018)](http://github.com/ms-ati/docile/compare/v1.3.0...v1.3.1)
8
51
 
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2012-2018 Marc Siegel
3
+ Copyright (c) 2012-2021 Marc Siegel
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -7,7 +7,7 @@
7
7
  [![Yard Docs](http://img.shields.io/badge/yard-docs-blue.svg)](http://rubydoc.info/github/ms-ati/docile)
8
8
  [![Docs Coverage](http://inch-ci.org/github/ms-ati/docile.png)](http://inch-ci.org/github/ms-ati/docile)
9
9
 
10
- [![Build Status](https://img.shields.io/travis/ms-ati/docile/master.svg)](https://travis-ci.org/ms-ati/docile)
10
+ [![Build Status](https://github.com/ms-ati/docile/actions/workflows/main.yml/badge.svg)](https://github.com/ms-ati/docile/actions/workflows/main.yml)
11
11
  [![Code Coverage](https://img.shields.io/codecov/c/github/ms-ati/docile.svg)](https://codecov.io/github/ms-ati/docile)
12
12
  [![Maintainability](https://api.codeclimate.com/v1/badges/79ca631bc123f7b83b34/maintainability)](https://codeclimate.com/github/ms-ati/docile/maintainability)
13
13
 
@@ -24,7 +24,7 @@ coding a bit more docile...
24
24
 
25
25
  ## Usage
26
26
 
27
- ### Basic: Ruby [Array](http://ruby-doc.org/core-2.2.2/Array.html) as DSL
27
+ ### Basic: Ruby [Array](http://ruby-doc.org/core-3.0.0/Array.html) as DSL
28
28
 
29
29
  Let's say that we want to make a DSL for modifying Array objects.
30
30
  Wouldn't it be great if we could just treat the methods of Array as a DSL?
@@ -269,11 +269,11 @@ Sometimes, you want to use an object as a DSL, but it doesn't quite fit the
269
269
  above.
270
270
 
271
271
  Instead of methods like
272
- [Array#push](http://www.ruby-doc.org/core-2.0/Array.html#method-i-push), which
272
+ [Array#push](http://www.ruby-doc.org/core-3.0.0/Array.html#method-i-push), which
273
273
  modifies the object at hand, it has methods like
274
- [String#reverse](http://www.ruby-doc.org/core-2.0/String.html#method-i-reverse),
274
+ [String#reverse](http://www.ruby-doc.org/core-3.0.0/String.html#method-i-reverse),
275
275
  which returns a new object without touching the original. Perhaps it's even
276
- [frozen](http://www.ruby-doc.org/core-2.0/Object.html#method-i-freeze) in
276
+ [frozen](http://www.ruby-doc.org/core-3.0.0/Object.html#method-i-freeze) in
277
277
  order to enforce [immutability](http://en.wikipedia.org/wiki/Immutable_object).
278
278
 
279
279
  Wouldn't it be great if we could just treat these methods as a DSL as well?
@@ -351,13 +351,19 @@ $ gem install docile
351
351
 
352
352
  ## Status
353
353
 
354
- Works on [all ruby versions since 1.8.7](https://github.com/ms-ati/docile/blob/master/.travis.yml), or so Travis CI [tells us](https://travis-ci.org/ms-ati/docile).
354
+ Works on [all currently supported ruby versions](https://github.com/ms-ati/docile/blob/master/.github/workflows/main.yml),
355
+ or so [Github Actions](https://github.com/ms-ati/docile/actions)
356
+ tells us.
355
357
 
356
- Used by some pretty cool gems to implement their DSLs, notably including [SimpleCov](https://github.com/colszowka/simplecov). Keep an eye out for new gems using Docile at the [Ruby Toolbox](https://www.ruby-toolbox.com/projects/docile).
358
+ Used by some pretty cool gems to implement their DSLs, notably including
359
+ [SimpleCov](https://github.com/colszowka/simplecov). Keep an eye out for new
360
+ gems using Docile at the
361
+ [Ruby Toolbox](https://www.ruby-toolbox.com/projects/docile).
357
362
 
358
363
  ## Release Policy
359
364
 
360
- Docile releases follow [Semantic Versioning 2.0.0](https://semver.org/spec/v2.0.0.html).
365
+ Docile releases follow
366
+ [Semantic Versioning 2.0.0](https://semver.org/spec/v2.0.0.html).
361
367
 
362
368
  ## Note on Patches/Pull Requests
363
369
 
@@ -372,10 +378,33 @@ Docile releases follow [Semantic Versioning 2.0.0](https://semver.org/spec/v2.0.
372
378
  commit by itself I can ignore when I pull)
373
379
  * Send me a pull request. Bonus points for topic branches.
374
380
 
375
- ## Copyright & License
381
+ ## Releasing
382
+
383
+ To make a new release of `Dile` to
384
+ [RubyGems](https://rubygems.org/gems/docile), first install the release
385
+ dependencies (e.g. `rake`) as follows:
386
+
387
+ ```shell
388
+ bundle config set --local with 'release'
389
+ bundle install
390
+ ```
376
391
 
377
- Copyright (c) 2012-2018 Marc Siegel.
392
+ Then carry out these steps:
378
393
 
379
- Licensed under the [MIT License](http://choosealicense.com/licenses/mit/), see [LICENSE](LICENSE) for details.
394
+ 1. Update `HISTORY.md`:
395
+ - Add an entry for the upcoming version _x.y.z_
396
+ - Move content from _Unreleased_ to the upcoming version _x.y.z_
397
+ - Commit with title `Update HISTORY.md for x.y.z`
398
+
399
+ 2. Update `lib/docile/version.rb`
400
+ - Replace with upcoming version _x.y.z_
401
+ - Commit with title `Bump version to x.y.z`
402
+
403
+ 3. `bundle exec rake release`
404
+
405
+ ## Copyright & License
380
406
 
407
+ Copyright (c) 2012-2021 Marc Siegel.
381
408
 
409
+ Licensed under the [MIT License](http://choosealicense.com/licenses/mit/),
410
+ see [LICENSE](LICENSE) for details.
data/Rakefile CHANGED
@@ -1,28 +1,14 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "rake/clean"
2
4
  require "bundler/gem_tasks"
3
5
  require "rspec/core/rake_task"
4
- require File.expand_path("on_what", File.dirname(__FILE__))
5
6
 
6
7
  # Default task for `rake` is to run rspec
7
- task :default => [:spec]
8
+ task default: [:spec]
8
9
 
9
10
  # Use default rspec rake task
10
11
  RSpec::Core::RakeTask.new
11
12
 
12
13
  # Configure `rake clobber` to delete all generated files
13
14
  CLOBBER.include("pkg", "doc", "coverage")
14
-
15
- # To limit needed compatibility with versions of dependencies, only configure
16
- # yard doc generation when *not* on Travis, JRuby, or < 2.0
17
- if !on_travis? && !on_jruby? && !on_less_than_2_0?
18
- require "github/markup"
19
- require "redcarpet"
20
- require "yard"
21
- require "yard/rake/yardoc_task"
22
-
23
- YARD::Rake::YardocTask.new do |t|
24
- OTHER_PATHS = %w()
25
- t.files = ["lib/**/*.rb", OTHER_PATHS]
26
- t.options = %w(--markup-provider=redcarpet --markup=markdown --main=README.md)
27
- end
28
- end
data/SECURITY.md ADDED
@@ -0,0 +1,18 @@
1
+ # Security Policy
2
+
3
+ ## Supported Versions
4
+
5
+ Use this section to tell people about which versions of your project are
6
+ currently being supported with security updates.
7
+
8
+ | Version | Supported |
9
+ | ------- | ------------------ |
10
+ | 1.3.x | :white_check_mark: |
11
+ | < 1.3 | :x: |
12
+
13
+ ## Reporting a Vulnerability
14
+
15
+ At this time, security issues and vulnerabilities in Docile should
16
+ be reported like any other issue. Please create an issue in the
17
+ [public issue tracker](https://github.com/ms-ati/docile/issues) on
18
+ Github.
data/docile.gemspec CHANGED
@@ -1,6 +1,6 @@
1
- $:.push File.expand_path("../lib", __FILE__)
2
- require File.expand_path("on_what", File.dirname(__FILE__))
3
- require "docile/version"
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/docile/version"
4
4
 
5
5
  Gem::Specification.new do |s|
6
6
  s.name = "docile"
@@ -18,37 +18,12 @@ Gem::Specification.new do |s|
18
18
  "semver.org."
19
19
  s.license = "MIT"
20
20
 
21
+ # Specify oldest supported Ruby version (2.5 to support JRuby 9.2.17.0)
22
+ s.required_ruby_version = ">= 2.5.0"
23
+
21
24
  # Files included in the gem
22
- s.files = `git ls-files -z`.split("\x0").reject do |f|
25
+ s.files = `git ls-files -z`.split("\x0").reject do |f|
23
26
  f.match(%r{^(test|spec|features)/})
24
27
  end
25
28
  s.require_paths = ["lib"]
26
-
27
- # Specify oldest supported Ruby version
28
- s.required_ruby_version = ">= 1.8.7"
29
-
30
- # Run rspec tests from rake even on old Ruby versions
31
- s.add_development_dependency "rake", "~> 10.5" if on_less_than_1_9_3? # Pin compatible rake on old rubies, see: https://github.com/travis-ci/travis.rb/issues/380
32
- s.add_development_dependency "rake", "< 11.0" unless on_less_than_1_9_3? # See http://stackoverflow.com/questions/35893584/nomethoderror-undefined-method-last-comment-after-upgrading-to-rake-11
33
- s.add_development_dependency "rspec", "~> 3.0"
34
-
35
- # Run code coverage where possible - not on Rubinius
36
- unless on_rubinius?
37
- # Pin versions for Travis builds on 1.9
38
- s.add_development_dependency "json", "< 2.0" if on_less_than_2_0?
39
-
40
- # Pin versions for Travis builds on 1.8
41
- s.add_development_dependency "mime-types" , "~> 1.25.1" if on_1_8?
42
- s.add_development_dependency "rest-client", "~> 1.6.8" if on_1_8?
43
- end
44
-
45
- # To limit needed compatibility with versions of dependencies, only configure
46
- # yard doc generation when *not* on Travis, JRuby, Rubinius, or < 2.0
47
- if !on_travis? && !on_jruby? && !on_rubinius? && !on_less_than_2_0?
48
- # Github flavored markdown in YARD documentation
49
- # http://blog.nikosd.com/2011/11/github-flavored-markdown-in-yard.html
50
- s.add_development_dependency "yard"
51
- s.add_development_dependency "redcarpet"
52
- s.add_development_dependency "github-markup"
53
- end
54
29
  end
data/lib/docile.rb CHANGED
@@ -1,7 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "docile/version"
2
4
  require "docile/execution"
3
5
  require "docile/fallback_context_proxy"
4
6
  require "docile/chaining_fallback_context_proxy"
7
+ require "docile/backtrace_filter"
5
8
 
6
9
  # Docile keeps your Ruby DSLs tame and well-behaved.
7
10
  module Docile
@@ -43,6 +46,8 @@ module Docile
43
46
  exec_in_proxy_context(dsl, FallbackContextProxy, *args, &block)
44
47
  dsl
45
48
  end
49
+
50
+ ruby2_keywords :dsl_eval if respond_to?(:ruby2_keywords, true)
46
51
  module_function :dsl_eval
47
52
 
48
53
  # Execute a block in the context of an object whose methods represent the
@@ -82,6 +87,10 @@ module Docile
82
87
  def dsl_eval_with_block_return(dsl, *args, &block)
83
88
  exec_in_proxy_context(dsl, FallbackContextProxy, *args, &block)
84
89
  end
90
+
91
+ if respond_to?(:ruby2_keywords, true)
92
+ ruby2_keywords :dsl_eval_with_block_return
93
+ end
85
94
  module_function :dsl_eval_with_block_return
86
95
 
87
96
  # Execute a block in the context of an immutable object whose methods,
@@ -119,5 +128,7 @@ module Docile
119
128
  def dsl_eval_immutable(dsl, *args, &block)
120
129
  exec_in_proxy_context(dsl, ChainingFallbackContextProxy, *args, &block)
121
130
  end
131
+
132
+ ruby2_keywords :dsl_eval_immutable if respond_to?(:ruby2_keywords, true)
122
133
  module_function :dsl_eval_immutable
123
134
  end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Docile
4
+ # @api private
5
+ #
6
+ # This is used to remove entries pointing to Docile's source files
7
+ # from {Exception#backtrace} and {Exception#backtrace_locations}.
8
+ #
9
+ # If {NoMethodError} is caught then the exception object will be extended
10
+ # by this module to add filter functionalities.
11
+ module BacktraceFilter
12
+ FILTER_PATTERN = %r{/lib/docile/}.freeze
13
+
14
+ def backtrace
15
+ super.reject { |trace| trace =~ FILTER_PATTERN }
16
+ end
17
+
18
+ if ::Exception.public_method_defined?(:backtrace_locations)
19
+ def backtrace_locations
20
+ super.reject { |location| location.absolute_path =~ FILTER_PATTERN }
21
+ end
22
+ end
23
+ end
24
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "docile/fallback_context_proxy"
2
4
 
3
5
  module Docile
@@ -10,11 +12,16 @@ module Docile
10
12
  # objects.
11
13
  #
12
14
  # @see Docile.dsl_eval_immutable
15
+ #
16
+ # rubocop:disable Style/MissingRespondToMissing
13
17
  class ChainingFallbackContextProxy < FallbackContextProxy
14
18
  # Proxy methods as in {FallbackContextProxy#method_missing}, replacing
15
19
  # `receiver` with the returned value.
16
20
  def method_missing(method, *args, &block)
17
21
  @__receiver__ = super(method, *args, &block)
18
22
  end
23
+
24
+ ruby2_keywords :method_missing if respond_to?(:ruby2_keywords, true)
19
25
  end
26
+ # rubocop:enable Style/MissingRespondToMissing
20
27
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Docile
2
4
  # @api private
3
5
  #
@@ -15,7 +17,14 @@ module Docile
15
17
  # @param block [Proc] the block of DSL commands to be executed
16
18
  # @return [Object] the return value of the block
17
19
  def exec_in_proxy_context(dsl, proxy_type, *args, &block)
18
- block_context = eval("self", block.binding)
20
+ block_context = eval("self", block.binding) # rubocop:disable Style/EvalWithLocation
21
+
22
+ # Use #equal? to test strict object identity (assuming that this dictum
23
+ # from the Ruby docs holds: "[u]nlike ==, the equal? method should never
24
+ # be overridden by subclasses as it is used to determine object
25
+ # identity")
26
+ return dsl.instance_exec(*args, &block) if dsl.equal?(block_context)
27
+
19
28
  proxy_context = proxy_type.new(dsl, block_context)
20
29
  begin
21
30
  block_context.instance_variables.each do |ivar|
@@ -31,11 +40,14 @@ module Docile
31
40
 
32
41
  block_context.instance_variables.each do |ivar|
33
42
  next unless proxy_context.instance_variables.include?(ivar)
43
+
34
44
  value_from_dsl_proxy = proxy_context.instance_variable_get(ivar)
35
45
  block_context.instance_variable_set(ivar, value_from_dsl_proxy)
36
46
  end
37
47
  end
38
48
  end
49
+
50
+ ruby2_keywords :exec_in_proxy_context if respond_to?(:ruby2_keywords, true)
39
51
  module_function :exec_in_proxy_context
40
52
  end
41
53
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "set"
2
4
 
3
5
  module Docile
@@ -13,14 +15,20 @@ module Docile
13
15
  # This is useful for implementing DSL evaluation in the context of an object.
14
16
  #
15
17
  # @see Docile.dsl_eval
18
+ #
19
+ # rubocop:disable Style/MissingRespondToMissing
16
20
  class FallbackContextProxy
17
21
  # The set of methods which will **not** be proxied, but instead answered
18
22
  # by this object directly.
19
23
  NON_PROXIED_METHODS = Set[:__send__, :object_id, :__id__, :==, :equal?,
20
- :"!", :"!=", :instance_exec, :instance_variables,
24
+ :!, :!=, :instance_exec, :instance_variables,
21
25
  :instance_variable_get, :instance_variable_set,
22
26
  :remove_instance_variable]
23
27
 
28
+ # The set of methods which will **not** fallback from the block's context
29
+ # to the dsl object.
30
+ NON_FALLBACK_METHODS = Set[:class, :self, :respond_to?, :instance_of?]
31
+
24
32
  # The set of instance variables which are local to this object and hidden.
25
33
  # All other instance variables will be copied in and out of this object
26
34
  # from the scope in which this proxy was created.
@@ -41,7 +49,7 @@ module Docile
41
49
 
42
50
  # Enables calling DSL methods from helper methods in the block's context
43
51
  unless fallback.respond_to?(:method_missing)
44
- # NOTE: There's no {#define_singleton_method} on Ruby 1.8.x
52
+ # NOTE: We could switch to {#define_singleton_method} on current Rubies
45
53
  singleton_class = (class << fallback; self; end)
46
54
 
47
55
  # instrument {#method_missing} on the block's context to fallback to
@@ -49,13 +57,20 @@ module Docile
49
57
  # contain calls to methods on the DSL object.
50
58
  singleton_class.
51
59
  send(:define_method, :method_missing) do |method, *args, &block|
52
- if receiver.respond_to?(method.to_sym)
60
+ m = method.to_sym
61
+ if !NON_FALLBACK_METHODS.member?(m) &&
62
+ !fallback.respond_to?(m) &&
63
+ receiver.respond_to?(m)
53
64
  receiver.__send__(method.to_sym, *args, &block)
54
65
  else
55
66
  super(method, *args, &block)
56
67
  end
57
68
  end
58
69
 
70
+ if singleton_class.respond_to?(:ruby2_keywords, true)
71
+ singleton_class.send(:ruby2_keywords, :method_missing)
72
+ end
73
+
59
74
  # instrument a helper method to remove the above instrumentation
60
75
  singleton_class.
61
76
  send(:define_method, :__docile_undo_fallback__) do
@@ -67,12 +82,8 @@ module Docile
67
82
 
68
83
  # @return [Array<Symbol>] Instance variable names, excluding
69
84
  # {NON_PROXIED_INSTANCE_VARIABLES}
70
- #
71
- # @note on Ruby 1.8.x, the instance variable names are actually of
72
- # type `String`.
73
85
  def instance_variables
74
- # Ruby 1.8.x returns string names, convert to symbols for compatibility
75
- super.select { |v| !NON_PROXIED_INSTANCE_VARIABLES.include?(v.to_sym) }
86
+ super.reject { |v| NON_PROXIED_INSTANCE_VARIABLES.include?(v) }
76
87
  end
77
88
 
78
89
  # Proxy all methods, excluding {NON_PROXIED_METHODS}, first to `receiver`
@@ -81,8 +92,16 @@ module Docile
81
92
  if @__receiver__.respond_to?(method.to_sym)
82
93
  @__receiver__.__send__(method.to_sym, *args, &block)
83
94
  else
84
- @__fallback__.__send__(method.to_sym, *args, &block)
95
+ begin
96
+ @__fallback__.__send__(method.to_sym, *args, &block)
97
+ rescue NoMethodError => e
98
+ e.extend(BacktraceFilter)
99
+ raise e
100
+ end
85
101
  end
86
102
  end
103
+
104
+ ruby2_keywords :method_missing if respond_to?(:ruby2_keywords, true)
87
105
  end
106
+ # rubocop:enable Style/MissingRespondToMissing
88
107
  end
@@ -1,4 +1,6 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Docile
2
4
  # The current version of this library
3
- VERSION = "1.3.1"
5
+ VERSION = "1.4.0"
4
6
  end
metadata CHANGED
@@ -1,85 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: docile
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.1
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marc Siegel
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-05-24 00:00:00.000000000 Z
12
- dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: rake
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "<"
18
- - !ruby/object:Gem::Version
19
- version: '11.0'
20
- type: :development
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "<"
25
- - !ruby/object:Gem::Version
26
- version: '11.0'
27
- - !ruby/object:Gem::Dependency
28
- name: rspec
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: '3.0'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: '3.0'
41
- - !ruby/object:Gem::Dependency
42
- name: yard
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: redcarpet
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: github-markup
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'
11
+ date: 2021-05-12 00:00:00.000000000 Z
12
+ dependencies: []
83
13
  description: "Docile treats the methods of a given ruby object as a DSL (domain specific
84
14
  language) within a given block. \n\nKiller feature: you can also reference methods,
85
15
  instance variables, and local variables from the original (non-DSL) context within
@@ -89,27 +19,30 @@ executables: []
89
19
  extensions: []
90
20
  extra_rdoc_files: []
91
21
  files:
22
+ - ".github/dependabot.yml"
23
+ - ".github/workflows/main.yml"
92
24
  - ".gitignore"
93
25
  - ".rspec"
94
- - ".travis.yml"
26
+ - ".rubocop.yml"
95
27
  - ".yardopts"
96
28
  - Gemfile
97
29
  - HISTORY.md
98
30
  - LICENSE
99
31
  - README.md
100
32
  - Rakefile
33
+ - SECURITY.md
101
34
  - docile.gemspec
102
35
  - lib/docile.rb
36
+ - lib/docile/backtrace_filter.rb
103
37
  - lib/docile/chaining_fallback_context_proxy.rb
104
38
  - lib/docile/execution.rb
105
39
  - lib/docile/fallback_context_proxy.rb
106
40
  - lib/docile/version.rb
107
- - on_what.rb
108
41
  homepage: https://ms-ati.github.io/docile/
109
42
  licenses:
110
43
  - MIT
111
44
  metadata: {}
112
- post_install_message:
45
+ post_install_message:
113
46
  rdoc_options: []
114
47
  require_paths:
115
48
  - lib
@@ -117,16 +50,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
117
50
  requirements:
118
51
  - - ">="
119
52
  - !ruby/object:Gem::Version
120
- version: 1.8.7
53
+ version: 2.5.0
121
54
  required_rubygems_version: !ruby/object:Gem::Requirement
122
55
  requirements:
123
56
  - - ">="
124
57
  - !ruby/object:Gem::Version
125
58
  version: '0'
126
59
  requirements: []
127
- rubyforge_project:
128
- rubygems_version: 2.7.4
129
- signing_key:
60
+ rubygems_version: 3.2.3
61
+ signing_key:
130
62
  specification_version: 4
131
63
  summary: Docile keeps your Ruby DSLs tame and well-behaved.
132
64
  test_files: []
data/.travis.yml DELETED
@@ -1,34 +0,0 @@
1
- language: ruby
2
-
3
- # Apparently sudo is required to test on Rubinius and JRuby-head
4
- sudo: required
5
-
6
- # See https://docs.travis-ci.com/user/languages/ruby/#Rubinius
7
- dist: trusty
8
-
9
- rvm:
10
- # MRI
11
- - ruby-head
12
- - 2.5
13
- - 2.4
14
- - 2.3
15
- - 2.2
16
- - 2.1
17
- - 1.9.3
18
- - 1.8.7
19
- - ree
20
- # JRuby
21
- - jruby-head
22
- - jruby-9.1.15.0 # Specific version to work around https://github.com/travis-ci/travis-ci/issues/9049
23
- - jruby-9.0
24
- - jruby-19mode
25
- - jruby-18mode
26
- # Rubinius
27
- - rubinius-3
28
-
29
- matrix:
30
- allow_failures:
31
- - rvm: ruby-head
32
- - rvm: jruby-head
33
- - rvm: rubinius-3
34
- fast_finish: true
data/on_what.rb DELETED
@@ -1,26 +0,0 @@
1
- # NOTE: Very simple tests for what system we are on, extracted for sharing
2
- # between Rakefile, gemspec, and spec_helper. Not for use in actual library.
3
-
4
- def on_travis?
5
- ENV["CI"] == "true"
6
- end
7
-
8
- def on_jruby?
9
- defined?(RUBY_ENGINE) && "jruby" == RUBY_ENGINE
10
- end
11
-
12
- def on_rubinius?
13
- defined?(RUBY_ENGINE) && "rbx" == RUBY_ENGINE
14
- end
15
-
16
- def on_1_8?
17
- RUBY_VERSION.start_with? "1.8"
18
- end
19
-
20
- def on_less_than_1_9_3?
21
- RUBY_VERSION < "1.9.3"
22
- end
23
-
24
- def on_less_than_2_0?
25
- RUBY_VERSION < "2.0.0"
26
- end