Class: Versacommerce::ThemeAPIClient::Resources::File

Inherits:
Versacommerce::ThemeAPIClient::Resource show all
Includes:
FileBehaviour
Defined in:
lib/versacommerce/theme_api_client/resources/file.rb

Instance Attribute Summary collapse

Attributes inherited from Versacommerce::ThemeAPIClient::Resource

#new_record

Class Method Summary collapse

Instance Method Summary collapse

Methods included from FileBehaviour

#==, #name, #path=

Methods inherited from Versacommerce::ThemeAPIClient::Resource

#assign_attributes, #initialize, #new_record?, #save, #update

Constructor Details

This class inherits a constructor from Versacommerce::ThemeAPIClient::Resource

Instance Attribute Details

#contentObject

Returns the value of attribute content.



71
72
73
# File 'lib/versacommerce/theme_api_client/resources/file.rb', line 71

def content
  @content
end

#statsObject

Returns the value of attribute stats.



72
73
74
# File 'lib/versacommerce/theme_api_client/resources/file.rb', line 72

def stats
  @stats
end

Class Method Details

.delete(path) ⇒ Object



31
32
33
34
# File 'lib/versacommerce/theme_api_client/resources/file.rb', line 31

def delete(path)
  fetcher.delete(file_path(path))
  true
end

.find(path, load_content: false) ⇒ Object



22
23
24
25
26
27
28
29
# File 'lib/versacommerce/theme_api_client/resources/file.rb', line 22

def find(path, load_content: false)
  response = fetcher.get(file_path(path))
  attributes = response.json

  new(attributes.merge(new_record: false)).tap do |file|
    file.reload_content if load_content && !file.has_content?
  end
end

.in_path(path = '', recursive = true) ⇒ Object



18
19
20
# File 'lib/versacommerce/theme_api_client/resources/file.rb', line 18

def in_path(path = '', recursive = true)
  recursive ? fetch_recursive(path) : fetch_non_recursive(path)
end

.model_nameObject



36
37
38
# File 'lib/versacommerce/theme_api_client/resources/file.rb', line 36

def model_name
  ActiveModel::Name.new(self, nil, 'File')
end

Instance Method Details

#deleteObject



74
75
76
77
78
79
80
# File 'lib/versacommerce/theme_api_client/resources/file.rb', line 74

def delete
  unless new_record?
    response = fetcher.delete(file_path(path))
    content_will_change!
    self.new_record = true
  end
end

#has_content?Boolean

Returns:

  • (Boolean)


89
90
91
# File 'lib/versacommerce/theme_api_client/resources/file.rb', line 89

def has_content?
  !!@content
end

#inspectObject



103
104
105
# File 'lib/versacommerce/theme_api_client/resources/file.rb', line 103

def inspect
  '#<File:0x%x>' % (object_id << 1)
end

#reload_contentObject



93
94
95
96
97
98
99
100
101
# File 'lib/versacommerce/theme_api_client/resources/file.rb', line 93

def reload_content
  unless new_record?
    response = fetcher.get(download_path(path))
    self.content = response.to_s
    clear_attribute_changes(:content)
  end

  self
end