lib/recurly/schema/request_caster.rb in recurly-3.0.0.beta.4 vs lib/recurly/schema/request_caster.rb in recurly-3.0.0.beta.5
- old
+ new
@@ -1,6 +1,6 @@
-require 'date'
+require "date"
module Recurly
class Schema
# *Note*: This class is for internal use.
# The RequestCaster turns mixed data into a pure Hash
@@ -23,17 +23,17 @@
# #=> {:account_code=>"benjamin", :address=>{:city=>"New Orleans"}}
#
# @param data [Hash,Resource,Request] The data to transform into a JSON Hash.
# @param schema [Schema] The schema to use to transform the data into a JSON Hash.
# @return [Hash] The pure Hash ready to be serialized into JSON.
- def cast(data, schema=self.schema)
+ def cast(data, schema = self.schema)
casted = {}
if data.is_a?(Resource) || data.is_a?(Request)
data = as_json(data, schema)
end
- data.each do |k,v|
+ data.each do |k, v|
schema_attr = schema.get_attribute(k)
norm_val = if v.respond_to?(:attributes)
cast(v, schema_attr.recurly_class.schema)
elsif v.is_a?(Array)
v.map do |elem|
@@ -57,10 +57,10 @@
private
def as_json(resource, schema)
writeable_attributes = schema.attributes.reject(&:read_only?).map(&:name)
- resource.attributes.select { |k,_| writeable_attributes.include?(k) }
+ resource.attributes.select { |k, _| writeable_attributes.include?(k) }
end
end
end
end