class Tck::Lambdas::AwsFunction

Attributes

conf[R]
name[R]

Public Class Methods

clean_tmps!() click to toggle source
# File lib/tck/lambdas/aws_function.rb, line 29
def self.clean_tmps!
  FileUtils.mkdir_p tmpdir
  FileUtils.rm_rf Dir.glob("#{tmpdir}/*")
end
new(name) click to toggle source
# File lib/tck/lambdas/aws_function.rb, line 34
def initialize(name)
  @name = name.to_s
  @conf = yaml && yaml[@name] || {}
  @timestamp = nil
end
tmpdir() click to toggle source
# File lib/tck/lambdas/aws_function.rb, line 11
def self.tmpdir
  @tmpdir ||= Dir.tmpdir + "/tck-lambdas"
end
yaml() click to toggle source
# File lib/tck/lambdas/aws_function.rb, line 15
def self.yaml
  if File.exist?('.lambdas.yml')
    current_timestamp = File.mtime('.lambdas.yml')
    if @timestamp == current_timestamp
      @yaml
    else
      @timestamp = current_timestamp
      @yaml = YAML.load_file('.lambdas.yml')
    end
  else
    {}
  end
end

Public Instance Methods

dir() click to toggle source
# File lib/tck/lambdas/aws_function.rb, line 53
def dir
  @dir ||= "lambdas/#{name}"
end
function_name() click to toggle source
# File lib/tck/lambdas/aws_function.rb, line 40
def function_name
  @conf['function-name'] || name
end
invoke_events_in_directory(event_type) { |filename, read| ... } click to toggle source
# File lib/tck/lambdas/aws_function.rb, line 65
def invoke_events_in_directory(event_type)
  Dir["lambdas/#{name}/test/#{event_type}/*.json"].each do |json_file|
    filename = File.basename(json_file)
    output = "#{tmpdir}/#{filename}.output"
    invoke_lambda json_file, output
    yield filename, File.read(output)
  end
end
invoke_lambda(payload_file, output_file) click to toggle source
# File lib/tck/lambdas/aws_function.rb, line 74
def invoke_lambda(payload_file, output_file)
  cmd = "aws lambda invoke " <<
          "--function-name #{@conf['function-name']}_test " <<
          "--payload file://#{payload_file} #{output_file}"
  puts "$ #{cmd}"
  `#{cmd}`
end
method_missing(method, *args, &block) click to toggle source
Calls superclass method
# File lib/tck/lambdas/aws_function.rb, line 48
def method_missing(method, *args, &block)  
  m = method.to_s
  @conf[m] || @conf[m.gsub("_","-")] || super
end
test_function_name() click to toggle source
# File lib/tck/lambdas/aws_function.rb, line 44
def test_function_name
  "#{@conf['function-name']}_test"
end
tmpdir() click to toggle source
# File lib/tck/lambdas/aws_function.rb, line 57
def tmpdir
  self.class.tmpdir
end
yaml() click to toggle source
# File lib/tck/lambdas/aws_function.rb, line 82
def yaml
  self.class.yaml
end
zip_file() click to toggle source
# File lib/tck/lambdas/aws_function.rb, line 61
def zip_file
  @zip_file ||= "#{Dir.pwd}/#{dir}/#{function_name}.zip"
end