class Percy::Client::Resource
A simple data container object used to pass data to create_snapshot.
Attributes
content[RW]
is_root[RW]
mimetype[RW]
path[RW]
resource_url[RW]
sha[RW]
Public Class Methods
new(resource_url, options = {})
click to toggle source
# File lib/percy/client/resources.rb, line 16 def initialize(resource_url, options = {}) @resource_url = resource_url if !options[:sha] && !options[:content] raise ArgumentError, 'Either "sha" or "content" must be given.' end @sha = options[:sha] || Digest::SHA256.hexdigest(options[:content]) @content = options[:content] @is_root = options[:is_root] @mimetype = options[:mimetype] # For optional convenience of temporarily storing the local content and path with this # object. These are never included when serialized. @content = options[:content] @path = options[:path] end
Public Instance Methods
==(other)
click to toggle source
# File lib/percy/client/resources.rb, line 46 def ==(other) other.is_a?(self.class) && other.sha == sha && other.resource_url == resource_url && other.mimetype == mimetype end
eql?(other)
click to toggle source
# File lib/percy/client/resources.rb, line 57 def eql?(other) self == other && hash == other.hash end
hash()
click to toggle source
# File lib/percy/client/resources.rb, line 53 def hash [sha, resource_url, mimetype].hash end
inspect()
click to toggle source
# File lib/percy/client/resources.rb, line 61 def inspect content_msg = content.nil? ? '' : "content.length: #{content.length}" "<Resource #{sha} #{resource_url} is_root:#{!!is_root} #{mimetype} #{content_msg}>" end
Also aliased as: to_s
serialize()
click to toggle source
# File lib/percy/client/resources.rb, line 34 def serialize { 'type' => 'resources', 'id' => sha, 'attributes' => { 'resource-url' => Addressable::URI.escape(resource_url), 'mimetype' => mimetype, 'is-root' => is_root, }, } end