Class: SwiftStorage::Node

Inherits:
Object
  • Object
show all
Includes:
Headers, Utils
Defined in:
lib/swift_storage/node.rb

Constant Summary

Constants included from Headers

Headers::ACCOUNT_TEMP_URL_KEY, Headers::AUTH_KEY, Headers::AUTH_TOKEN, Headers::AUTH_USER, Headers::CACHE_CONTROL, Headers::CONNECTION, Headers::CONTAINER_READ, Headers::CONTAINER_WRITE, Headers::CONTENT_DISPOSITION, Headers::CONTENT_TYPE, Headers::DELETE_AFTER, Headers::DELETE_AT, Headers::DESTINATION, Headers::EXPIRES, Headers::OBJECT_MANIFEST, Headers::PROXY_CONNECTION, Headers::STORAGE_TOKEN, Headers::STORAGE_URL

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils

#hmac, #sig_to_hex, #struct

Constructor Details

#initialize(parent, name = nil) ⇒ Node

Returns a new instance of Node.



7
8
9
10
# File 'lib/swift_storage/node.rb', line 7

def initialize(parent, name=nil)
  @parent = parent
  @name = name
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



5
6
7
# File 'lib/swift_storage/node.rb', line 5

def name
  @name
end

#parentObject

Returns the value of attribute parent.



5
6
7
# File 'lib/swift_storage/node.rb', line 5

def parent
  @parent
end

Instance Method Details

#clear_cacheObject



79
80
81
82
# File 'lib/swift_storage/node.rb', line 79

def clear_cache
  @headers = nil
  @metadata = nil
end

#deleteObject



91
92
93
# File 'lib/swift_storage/node.rb', line 91

def delete
  request(relative_path, :method => :delete)
end

#delete_if_existsObject



95
96
97
98
99
# File 'lib/swift_storage/node.rb', line 95

def delete_if_exists
  delete
rescue SwiftStorage::Errors::NotFoundError
  false
end

#exists?Boolean

Returns:

  • (Boolean)


84
85
86
87
88
89
# File 'lib/swift_storage/node.rb', line 84

def exists?
  request(relative_path, :method => :head)
  true
rescue SwiftStorage::Errors::NotFoundError
  false
end

#get_lines(path, prefix: nil) ⇒ Object



32
33
34
35
36
37
38
39
40
41
# File 'lib/swift_storage/node.rb', line 32

def get_lines(path, prefix: nil)
  headers = {'Accept' => 'text/plain'}
  response = request(path, :headers => headers, :params => {:prefix => prefix})
  body = response.body
  if body.nil? || body.empty?
    []
  else
    body.lines.map(&:strip)
  end
end

#headersObject



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/swift_storage/node.rb', line 51

def headers
  return @headers if @headers

  response ||= request(relative_path, :method => :head)

  h = {}
   = h[:metadata] = {}
  response.to_hash.each_pair do |k,v|
    if k =~ /^X-#{self.class.header_name}-Meta-?(.+)/i
      k = $1
      t = 
    elsif k =~ /^X-#{self.class.header_name}-?(.+)/i
      k = $1
      t = h
    else
      t = h
    end
    k = k.downcase.gsub(/\W/, '_')
    v = v.first if v.respond_to?(:to_ary)
    t[k] = v
  end
  @headers = struct(h)
end

#metadataObject



75
76
77
# File 'lib/swift_storage/node.rb', line 75

def 
  @metadata ||= struct(headers.)
end

#relative_pathObject

Raises:

  • (NotImplemented)


47
48
49
# File 'lib/swift_storage/node.rb', line 47

def relative_path
  raise NotImplemented
end

#request(*args) ⇒ Object



12
13
14
# File 'lib/swift_storage/node.rb', line 12

def request(*args)
  service.request(*args)
end

#serviceSwiftStorage::Service

Returns the service for this node

Returns:



21
22
23
24
25
26
27
28
29
30
# File 'lib/swift_storage/node.rb', line 21

def service
  unless defined?(@service)
    p = parent
    while p && !(SwiftStorage::Service === p)
       p = p.parent
    end
    @service = p
  end
  @service
end

#to_sObject



43
44
45
# File 'lib/swift_storage/node.rb', line 43

def to_s
  "#<#{self.class.name} #{name}>"
end