Class: Percy::Client::Resource
- Inherits:
-
Object
- Object
- Percy::Client::Resource
- Defined in:
- lib/percy/client/resources.rb
Overview
A simple data container object used to pass data to create_snapshot.
Instance Attribute Summary collapse
-
#content ⇒ Object
Returns the value of attribute content.
-
#is_root ⇒ Object
Returns the value of attribute is_root.
-
#mimetype ⇒ Object
Returns the value of attribute mimetype.
-
#path ⇒ Object
Returns the value of attribute path.
-
#resource_url ⇒ Object
Returns the value of attribute resource_url.
-
#root_for_width ⇒ Object
Returns the value of attribute root_for_width.
-
#sha ⇒ Object
Returns the value of attribute sha.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #eql?(other) ⇒ Boolean
- #hash ⇒ Object
-
#initialize(resource_url, options = {}) ⇒ Resource
constructor
A new instance of Resource.
- #inspect ⇒ Object (also: #to_s)
- #serialize ⇒ Object
Constructor Details
#initialize(resource_url, options = {}) ⇒ Resource
Returns a new instance of Resource.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/percy/client/resources.rb', line 17 def initialize(resource_url, = {}) @resource_url = resource_url if ![:sha] && ![:content] raise ArgumentError, 'Either "sha" or "content" must be given.' end @sha = [:sha] || Digest::SHA256.hexdigest([:content]) @content = [:content] @is_root = [:is_root] @root_for_width = [:root_for_width] @mimetype = [:mimetype] # For optional convenience of temporarily storing the local content and path with this # object. These are never included when serialized. @content = [:content] @path = [:path] end |
Instance Attribute Details
#content ⇒ Object
Returns the value of attribute content.
14 15 16 |
# File 'lib/percy/client/resources.rb', line 14 def content @content end |
#is_root ⇒ Object
Returns the value of attribute is_root.
11 12 13 |
# File 'lib/percy/client/resources.rb', line 11 def is_root @is_root end |
#mimetype ⇒ Object
Returns the value of attribute mimetype.
13 14 15 |
# File 'lib/percy/client/resources.rb', line 13 def mimetype @mimetype end |
#path ⇒ Object
Returns the value of attribute path.
15 16 17 |
# File 'lib/percy/client/resources.rb', line 15 def path @path end |
#resource_url ⇒ Object
Returns the value of attribute resource_url.
10 11 12 |
# File 'lib/percy/client/resources.rb', line 10 def resource_url @resource_url end |
#root_for_width ⇒ Object
Returns the value of attribute root_for_width.
12 13 14 |
# File 'lib/percy/client/resources.rb', line 12 def root_for_width @root_for_width end |
#sha ⇒ Object
Returns the value of attribute sha.
9 10 11 |
# File 'lib/percy/client/resources.rb', line 9 def sha @sha end |
Instance Method Details
#==(other) ⇒ Object
49 50 51 52 53 54 |
# File 'lib/percy/client/resources.rb', line 49 def ==(other) other.is_a?(self.class) && other.sha == sha && other.resource_url == resource_url && other.mimetype == mimetype end |
#eql?(other) ⇒ Boolean
60 61 62 |
# File 'lib/percy/client/resources.rb', line 60 def eql?(other) self == other && hash == other.hash end |
#hash ⇒ Object
56 57 58 |
# File 'lib/percy/client/resources.rb', line 56 def hash [sha, resource_url, mimetype].hash end |
#inspect ⇒ Object Also known as: to_s
64 65 66 67 |
# File 'lib/percy/client/resources.rb', line 64 def inspect content_msg = content.nil? ? '' : "content.length: #{content.length}" "<Resource #{sha} #{resource_url} root_for_width:#{root_for_width} is_root:#{!!is_root} #{mimetype} #{content_msg}>" end |
#serialize ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/percy/client/resources.rb', line 36 def serialize { 'type' => 'resources', 'id' => sha, 'attributes' => { 'resource-url' => Addressable::URI.escape(resource_url), 'mimetype' => mimetype, 'is-root' => is_root, 'for-widths' => root_for_width ? [root_for_width] : nil, }, } end |