lib/contentful/file.rb in contentful-2.1.3 vs lib/contentful/file.rb in contentful-2.2.0

- old
+ new

@@ -1,12 +1,20 @@ module Contentful # An Assets's file info class File - attr_reader :file_name, :content_type, :details, :url - def initialize(json) - @file_name = json.fetch('fileName', nil) - @content_type = json.fetch('contentType', nil) - @details = json.fetch('details', nil) - @url = json.fetch('url', nil) + def initialize(json, configuration) + @configuration = configuration + + define_fields!(json) + end + + private + + def define_fields!(json) + json.each do |k, v| + define_singleton_method Support.snakify(k, @configuration[:use_camel_case]) do + v + end + end end end end