Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions lib/json_api_client/helpers/dynamic_attributes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def attributes=(attrs = {})

return @attributes unless attrs.present?
attrs.each do |key, value|
send("#{key}=", value)
self[key] = value
end
end

Expand All @@ -20,7 +20,8 @@ def [](key)
end

def []=(key, value)
set_attribute(key, value)
normalized_key = normalize_name(key)
set_attribute(normalized_key, value)
end

def respond_to_missing?(method, include_private = false)
Expand All @@ -37,12 +38,16 @@ def has_attribute?(attr_name)

protected

def normalize_name(name)
if key_formatter
key_formatter.unformat(name.to_s)
else
name.to_s
end
end

def method_missing(method, *args, &block)
normalized_method = if key_formatter
key_formatter.unformat(method.to_s)
else
method.to_s
end
normalized_method = normalize_name(method)

if normalized_method =~ /^(.*)=$/
set_attribute($1, args.first)
Expand Down