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.
-
#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.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/percy/client/resources.rb', line 16 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] @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.
13 14 15 |
# File 'lib/percy/client/resources.rb', line 13 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.
12 13 14 |
# File 'lib/percy/client/resources.rb', line 12 def mimetype @mimetype end |
#path ⇒ Object
Returns the value of attribute path.
14 15 16 |
# File 'lib/percy/client/resources.rb', line 14 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 |
#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
46 47 48 49 50 51 |
# 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) ⇒ Boolean
57 58 59 |
# File 'lib/percy/client/resources.rb', line 57 def eql?(other) self == other && hash == other.hash end |
#hash ⇒ Object
53 54 55 |
# File 'lib/percy/client/resources.rb', line 53 def hash [sha, resource_url, mimetype].hash end |
#inspect ⇒ Object Also known as: to_s
61 62 63 64 |
# 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 |
#serialize ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 |
# 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 |