Skip to content

Commit

Permalink
fix ActiveRecord::Base check
Browse files Browse the repository at this point in the history
  • Loading branch information
yosiat committed Oct 31, 2024
1 parent 6e2f185 commit d09cbe5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/panko/impl/attributes_writer/creator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
module Panko::Impl
module AttributesWriter
def self.create(object)
if defined?(ActiveRecord::Base) && object.is_a?(ActiveRecord::Base)
if defined?(::ActiveRecord::Base) && object.is_a?(::ActiveRecord::Base)
return ActiveRecord::Writer.new
end

Expand Down
8 changes: 5 additions & 3 deletions lib/panko/serialization_descriptor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -152,16 +152,18 @@ def apply_association_filters(associations, only_filters, except_filters)
end
end

EMPTY_OBJECT = {}.freeze

def resolve_filters(options, filter)
filters = options.fetch(filter, {})
return filters, {} if filters.is_a? Array
filters = options.fetch(filter, EMPTY_OBJECT)
return filters, EMPTY_OBJECT if filters.is_a? Array

# hash filters looks like this
# { instance: [:a], foo: [:b] }
# which mean, for the current instance use `[:a]` as filter
# and for association named `foo` use `[:b]`

return [], {} if filters.empty?
return [], EMPTY_OBJECT if filters.empty?

attributes_filters = filters.fetch(:instance, [])
association_filters = filters.except(:instance)
Expand Down

0 comments on commit d09cbe5

Please sign in to comment.