Class: Versacommerce::ThemeAPIClient::Relation

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/versacommerce/theme_api_client/relation.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, attributes = {}) ⇒ Relation

Returns a new instance of Relation.



9
10
11
12
13
14
15
# File 'lib/versacommerce/theme_api_client/relation.rb', line 9

def initialize(client, attributes = {})
  @client = client

  attributes.each do |key, value|
    public_send("#{key}=", value)
  end
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



7
8
9
# File 'lib/versacommerce/theme_api_client/relation.rb', line 7

def client
  @client
end

#pathObject

Returns the value of attribute path.



7
8
9
# File 'lib/versacommerce/theme_api_client/relation.rb', line 7

def path
  @path
end

#recursiveObject

Returns the value of attribute recursive.



6
7
8
# File 'lib/versacommerce/theme_api_client/relation.rb', line 6

def recursive
  @recursive
end

Instance Method Details

#build(attributes = {}) ⇒ Object



28
29
30
31
# File 'lib/versacommerce/theme_api_client/relation.rb', line 28

def build(attributes = {})
  path = combined_path(attributes[:path])
  resource_class.new(attributes.merge(path: path))
end

#create(attributes = {}) ⇒ Object



33
34
35
36
37
# File 'lib/versacommerce/theme_api_client/relation.rb', line 33

def create(attributes = {})
  build(attributes).tap do |object|
    object.save
  end
end

#delete(path) ⇒ Object



39
40
41
# File 'lib/versacommerce/theme_api_client/relation.rb', line 39

def delete(path)
  resource_class.delete(combined_path(path))
end

#each(&block) ⇒ Object



43
44
45
46
# File 'lib/versacommerce/theme_api_client/relation.rb', line 43

def each(&block)
  files = resource_class.in_path(path, recursive)
  files.each(&block)
end

#find(path, **options) ⇒ Object



17
18
19
# File 'lib/versacommerce/theme_api_client/relation.rb', line 17

def find(path, **options)
  resource_class.find(combined_path(path), **options)
end

#in_path(path, **options) ⇒ Object



21
22
23
24
25
26
# File 'lib/versacommerce/theme_api_client/relation.rb', line 21

def in_path(path, **options)
  tap do |relation|
    relation.path = path
    relation.recursive = options[:recursive] if options.key?(:recursive)
  end
end

#inspectObject



57
58
59
# File 'lib/versacommerce/theme_api_client/relation.rb', line 57

def inspect
  to_s
end