Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What happens if we recursively map hashes in response to StrictOpenStuct? #135

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/restful_resource/open_object.rb
@@ -1,7 +1,7 @@
module RestfulResource
class OpenObject
def initialize(attributes = {}, _hack_for_activeresource = false)
@inner_object = StrictOpenStruct.new(attributes)
@inner_object = StrictOpenStruct.recursively_build(attributes)
end

def method_missing(method, *args, &block)
Expand Down
6 changes: 6 additions & 0 deletions lib/restful_resource/strict_open_struct.rb
@@ -1,5 +1,11 @@
module RestfulResource
class StrictOpenStruct < ::OpenStruct
def self.recursively_build(attributes)
new(attributes.transform_values do |attr|
attr.is_a?(Hash) ? recursively_build(attr) : attr
end)
end

deprecate :dig, :[], deprecator: Deprecator.build
end
end