Class: Lambchop::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/lambchop/client.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, path, options = {}) ⇒ Client

Returns a new instance of Client.



6
7
8
9
10
11
# File 'lib/lambchop/client.rb', line 6

def initialize(source, path, options = {})
  @source  = source
  @path    = path
  @client  = options[:client] || Aws::Lambda::Client.new
  @options = options
end

Class Method Details

.start(source, path, options = {}) ⇒ Object



2
3
4
# File 'lib/lambchop/client.rb', line 2

def self.start(source, path, options = {})
  self.new(source, path, options).start
end

Instance Method Details

#startObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/lambchop/client.rb', line 13

def start
  src = @source

  if @options[:use_erb]
    src = ERB.new(src, nil, '-').result
  end

  src = Lambchop::Utils.remove_shebang(src)
  config, src = Lambchop::Utils.parse_magic_comment(src)

  config['function_name'] ||= File.basename(@path, '.js')
  config['runtime'] ||= 'nodejs'
  function_name = config['function_name']
  include_files = config.delete('include_files')

  create_or_update_function(config, src, include_files)

  exit if @options[:detach]

  trap(:INT) { exit } unless Lambchop::Utils.debug?
  Lambchop::WatchDog.start(function_name, @options[:watch_dog] || {})

  sleep
end