Skip to content

Commit

Permalink
Merge dfe2e8c into bfb4da5
Browse files Browse the repository at this point in the history
  • Loading branch information
nbeyer committed Feb 19, 2020
2 parents bfb4da5 + dfe2e8c commit bbc6da4
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 22 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@
* Your contribution here.

#### Fixes

* [#1995](https://github.com/ruby-grape/grape/pull/1995): Address some Ruby warnings - [@nbeyer](https://github.com/nbeyer).
* [#1993](https://github.com/ruby-grape/grape/pull/1993): Lazy join allow header - [@ericproulx](https://github.com/ericproulx).
* [#1987](https://github.com/ruby-grape/grape/pull/1987): Re-add exactly_one_of mutually exclusive error message - [@ZeroInputCtrl](https://github.com/ZeroInputCtrl).
* [#1977](https://github.com/ruby-grape/grape/pull/1977): Skip validation for a file if it is optional and nil - [@dnesteryuk](https://github.com/dnesteryuk).
* [#1976](https://github.com/ruby-grape/grape/pull/1976): Ensure classes/modules listed for autoload really exist - [@dnesteryuk](https://github.com/dnesteryuk).
* [#1971](https://github.com/ruby-grape/grape/pull/1971): Fix BigDecimal coercion - [@FlickStuart](https://github.com/FlickStuart).
* [#1968](https://github.com/ruby-grape/grape/pull/1968): Fix args forwarding in Grape::Middleware::Stack#merge_with for ruby 2.7.0 - [@dm1try](https://github.com/dm1try).
* [#1988](https://github.com/ruby-grape/grape/pull/1988): Refactored the full_messages method and stop overriding full_message - [@hosseintoussi](https://github.com/hosseintoussi).

### 1.3.0 (2020/01/11)

#### Features
Expand Down
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ group :test do
gem 'grape-entity', '~> 0.6'
gem 'maruku'
gem 'mime-types'
gem 'multi_xml'
gem 'rack-jsonp', require: 'rack/jsonp'
gem 'rack-test', '~> 1.1.0'
gem 'rspec', '~> 3.0'
Expand Down
2 changes: 1 addition & 1 deletion lib/grape/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module Grape
# should subclass this class in order to build an API.
class API
# Class methods that we want to call on the API rather than on the API object
NON_OVERRIDABLE = (Class.new.methods + %i[call call! configuration compile!]).freeze
NON_OVERRIDABLE = (Class.new.methods + %i[call call! configuration compile! inherited]).freeze

class << self
attr_accessor :base_instance, :instances
Expand Down
2 changes: 1 addition & 1 deletion lib/grape/dsl/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def api_changed(new_api)
protected

def process_named_params
return unless @named_params && @named_params.any?
return unless instance_variable_defined?(:@named_params) && @named_params && @named_params.any?
api.namespace_stackable(:named_params, @named_params)
end
end
Expand Down
17 changes: 9 additions & 8 deletions lib/grape/dsl/inside_route.rb
Original file line number Diff line number Diff line change
Expand Up @@ -182,12 +182,12 @@ def status(status = nil)
when Integer
@status = status
when nil
return @status if @status
return @status if instance_variable_defined?(:@status) && @status
case request.request_method.to_s.upcase
when Grape::Http::Headers::POST
201
when Grape::Http::Headers::DELETE
if @body.present?
if instance_variable_defined?(:@body) && @body.present?
200
else
204
Expand Down Expand Up @@ -238,7 +238,7 @@ def body(value = nil)
@body = ''
status 204
else
@body
instance_variable_defined?(:@body) ? @body : nil
end
end

Expand Down Expand Up @@ -272,7 +272,7 @@ def file(value = nil)
warn '[DEPRECATION] Argument as FileStreamer-like object is deprecated. Use path to file instead.'
@file = Grape::ServeFile::FileResponse.new(value)
else
@file
instance_variable_defined?(:@file) ? @file : nil
end
end

Expand Down Expand Up @@ -331,11 +331,12 @@ def present(*args)
end

representation = { root => representation } if root

if key
representation = (@body || {}).merge(key => representation)
elsif entity_class.present? && @body
representation = (body || {}).merge(key => representation)
elsif entity_class.present? && body
raise ArgumentError, "Representation of type #{representation.class} cannot be merged." unless representation.respond_to?(:merge)
representation = @body.merge(representation)
representation = body.merge(representation)
end

body representation
Expand Down Expand Up @@ -387,7 +388,7 @@ def entity_class_for_obj(object, options)
def entity_representation_for(entity_class, object, options)
embeds = { env: env }
embeds[:version] = env[Grape::Env::API_VERSION] if env[Grape::Env::API_VERSION]
entity_class.represent(object, **embeds.merge(options))
entity_class.represent(object, embeds.merge(options))
end
end
end
Expand Down
8 changes: 4 additions & 4 deletions lib/grape/dsl/parameters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def requires(*attrs, &block)

opts = attrs.extract_options!.clone
opts[:presence] = { value: true, message: opts[:message] }
opts = @group.merge(opts) if @group
opts = @group.merge(opts) if instance_variable_defined?(:@group) && @group

if opts[:using]
require_required_and_optional_fields(attrs.first, opts)
Expand All @@ -146,7 +146,7 @@ def optional(*attrs, &block)

opts = attrs.extract_options!.clone
type = opts[:type]
opts = @group.merge(opts) if @group
opts = @group.merge(opts) if instance_variable_defined?(:@group) && @group

# check type for optional parameter group
if attrs && block_given?
Expand Down Expand Up @@ -243,8 +243,8 @@ def map_params(params, element)
# @return hash of parameters relevant for the current scope
# @api private
def params(params)
params = @parent.params(params) if @parent
params = map_params(params, @element) if @element
params = @parent.params(params) if instance_variable_defined?(:@parent) && @parent
params = map_params(params, @element) if instance_variable_defined?(:@element) && @element
params
end

Expand Down
4 changes: 3 additions & 1 deletion lib/grape/dsl/routing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def version(*args, &block)
end
end

@versions.last unless @versions.nil?
@versions.last if instance_variable_defined?(:@versions) && @versions
end

# Define a root URL prefix for your entire API.
Expand Down Expand Up @@ -163,6 +163,8 @@ def route(methods, paths = ['/'], route_options = {}, &block)
# end
# end
def namespace(space = nil, options = {}, &block)
@namespace_description = nil unless instance_variable_defined?(:@namespace_description) && @namespace_description

if space || block_given?
within_namespace do
previous_namespace_description = @namespace_description
Expand Down
13 changes: 7 additions & 6 deletions spec/grape/api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -935,7 +935,7 @@ class DummyFormatClass

it 'adds a before filter to current and child namespaces only' do
subject.get '/' do
"root - #{@foo}"
"root - #{instance_variable_defined?(:@foo) ? @foo : nil}"
end
subject.namespace :blah do
before { @foo = 'foo' }
Expand Down Expand Up @@ -3677,12 +3677,13 @@ def before
end
end
context ':serializable_hash' do
before(:each) do
class SerializableHashExample
def serializable_hash
{ abc: 'def' }
end
class SerializableHashExample
def serializable_hash
{ abc: 'def' }
end
end

before(:each) do
subject.format :serializable_hash
end
it 'instance' do
Expand Down
2 changes: 1 addition & 1 deletion spec/grape/validations/instance_behaivour_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
let(:validator_type) do
Class.new(Grape::Validations::Base) do
def validate_param!(_attr_name, _params)
if @instance_variable
if instance_variable_defined?(:@instance_variable) && @instance_variable
raise Grape::Exceptions::Validation.new(params: ['params'],
message: 'This should never happen')
end
Expand Down
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def read_chunks(body)
config.include Spec::Support::Helpers
config.raise_errors_for_deprecations!
config.filter_run_when_matching :focus
config.warnings = true

config.before(:each) { Grape::Util::InheritableSetting.reset_global! }

Expand Down

0 comments on commit bbc6da4

Please sign in to comment.