Class: HAL::S3::DirectoryIndex

Inherits:
Object
  • Object
show all
Defined in:
lib/hal/s3.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uri, relation_name: 'items', self_url: nil) ⇒ DirectoryIndex

Returns a new instance of DirectoryIndex.



10
11
12
13
14
15
16
17
18
# File 'lib/hal/s3.rb', line 10

def initialize(uri, relation_name: 'items', self_url: nil)
  @uri           = URI(uri)
  @relation_name = relation_name
  @self_url      = self_url

  options = {}
  options[:endpoint] = "https://s3-#{ENV['AWS_REGION']}.amazonaws.com" if ENV['AWS_REGION']
  @s3 = Aws::S3::Client.new(options)
end

Instance Attribute Details

#relation_nameObject (readonly)

Returns the value of attribute relation_name.



8
9
10
# File 'lib/hal/s3.rb', line 8

def relation_name
  @relation_name
end

#self_urlObject (readonly)

Returns the value of attribute self_url.



8
9
10
# File 'lib/hal/s3.rb', line 8

def self_url
  @self_url
end

#uriObject (readonly)

Returns the value of attribute uri.



8
9
10
# File 'lib/hal/s3.rb', line 8

def uri
  @uri
end

Instance Method Details

#to_hashObject



20
21
22
23
24
25
26
# File 'lib/hal/s3.rb', line 20

def to_hash
  data = {
    '_links' => {'self' => {'href' => self_url}}
  }
  data['_links'][relation_name] = hrefs
  data
end

#to_json(pretty: false) ⇒ Object



28
29
30
# File 'lib/hal/s3.rb', line 28

def to_json(pretty: false)
  pretty ? JSON.pretty_unparse(to_hash) : to_hash.to_json
end