Sha256: 5faa75e04b6298b2a8424aec6f9d3556b3801cc8b1ec2f102c8e7dba39d7be8f

Contents?: true

Size: 721 Bytes

Versions: 11

Compression:

Stored size: 721 Bytes

Contents

module AppleNews
  module Resource
    extend ActiveSupport::Concern

    included do
      def update_with_data(data)
        load_properties(data)
      end

      def resource_url
        File.join(@resource_path, id)
      end

      private

      def hydrate!
        if respond_to?(:load_properties)
          load_properties(fetch_data['data'])
        else
          set_read_only_properties(fetch_data['data'])
        end
      end

      def fetch_data
        request = AppleNews::Request::Get.new(resource_url)
        request.call
      end

      def set_read_only_properties(data)
        data.each do |k, v|
          instance_variable_set("@#{k.underscore}", v)
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
apple-news-0.4.2 lib/apple-news/resource.rb
apple-news-0.4.1 lib/apple-news/resource.rb
apple-news-0.4.0 lib/apple-news/resource.rb
apple-news-0.3.1 lib/apple-news/resource.rb
apple-news-0.3.0 lib/apple-news/resource.rb
apple-news-0.2.5 lib/apple-news/resource.rb
apple-news-0.2.4 lib/apple-news/resource.rb
apple-news-0.2.3 lib/apple-news/resource.rb
apple-news-0.2.2 lib/apple-news/resource.rb
apple-news-0.2.1 lib/apple-news/resource.rb
apple-news-0.2.0 lib/apple-news/resource.rb