Skip to content

Commit

Permalink
No more default values, just set value if not nil
Browse files Browse the repository at this point in the history
Add value variable back
  • Loading branch information
Che-Chris committed Jan 14, 2019
1 parent 42ddab3 commit cb66650
Showing 1 changed file with 1 addition and 8 deletions.
9 changes: 1 addition & 8 deletions lib/nylas/model/attributes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def merge(new_data)
def to_h(keys: attribute_definitions.keys)
keys.each_with_object({}) do |key, casted_data|
value = attribute_definitions[key].serialize(self[key])
casted_data[key] = defaulted_value(value)
casted_data[key] = value unless value.nil?
end
end

Expand All @@ -44,13 +44,6 @@ def serialize(keys: attribute_definitions.keys)
private def default_attributes
attribute_definitions.keys.zip([]).to_h
end

private def defaulted_value(value)
result = value unless value.nil? || (value.respond_to?(:empty?) && value.empty?)
result ||= [] if value.is_a?(Array)
result ||= "" unless [true, false].include?(value)
result
end
end
end
end

0 comments on commit cb66650

Please sign in to comment.