Class: Lamma::Alias

Inherits:
Object
  • Object
show all
Defined in:
lib/lamma/alias.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(function, name, version = nil, description = nil) ⇒ Alias

Returns a new instance of Alias.



5
6
7
8
9
10
# File 'lib/lamma/alias.rb', line 5

def initialize(function, name, version=nil, description=nil)
  @function = function
  @name = name
  @version = version
  @description = description
end

Instance Attribute Details

#description=(value) ⇒ Object

Sets the attribute description

Parameters:

  • value

    the value to set the attribute description to.



3
4
5
# File 'lib/lamma/alias.rb', line 3

def description=(value)
  @description = value
end

#versionObject

Returns the value of attribute version.



3
4
5
# File 'lib/lamma/alias.rb', line 3

def version
  @version
end

Instance Method Details

#createObject



12
13
14
15
16
17
18
19
# File 'lib/lamma/alias.rb', line 12

def create
  lambda_client.create_alias({
    function_name: @function.name,
    name: name, # 'name' indicates the self
    function_version: @version,
    description: description
  })
end

#create_or_updateObject



30
31
32
33
34
35
36
# File 'lib/lamma/alias.rb', line 30

def create_or_update
  if remote_exist?
    update
  else
    create
  end
end

#nameObject



38
39
40
# File 'lib/lamma/alias.rb', line 38

def name
  @name.upcase
end

#remote_exist?Boolean

Returns:

  • (Boolean)


42
43
44
45
46
47
48
49
50
51
# File 'lib/lamma/alias.rb', line 42

def remote_exist?
  begin
    lambda_client.get_alias({
      function_name: @function.name,
      name: name
    })
  rescue Aws::Lambda::Errors::ResourceNotFoundException
    false
  end
end

#remote_versionObject



53
54
55
56
57
58
59
60
61
62
# File 'lib/lamma/alias.rb', line 53

def remote_version
  begin
    lambda_client.get_alias({
      function_name: @function.name,
      name: name
    }).function_version
  rescue Aws::Lambda::Errors::ResourceNotFoundException
    nil
  end
end

#updateObject



21
22
23
24
25
26
27
28
# File 'lib/lamma/alias.rb', line 21

def update
  lambda_client.update_alias({
    function_name: @function.name,
    name: name, # 'name' indicates the self
    function_version: @version,
    description: description
  })
end