Class: Tck::Lambdas::AwsFunction
- Inherits:
-
Object
- Object
- Tck::Lambdas::AwsFunction
show all
- Defined in:
- lib/tck/lambdas/aws_function.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of AwsFunction.
34
35
36
37
38
|
# File 'lib/tck/lambdas/aws_function.rb', line 34
def initialize(name)
@name = name.to_s
@conf = yaml && yaml[@name] || {}
@timestamp = nil
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
48
49
50
51
|
# 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
|
Instance Attribute Details
#conf ⇒ Object
Returns the value of attribute conf.
9
10
11
|
# File 'lib/tck/lambdas/aws_function.rb', line 9
def conf
@conf
end
|
#name ⇒ Object
Returns the value of attribute name.
8
9
10
|
# File 'lib/tck/lambdas/aws_function.rb', line 8
def name
@name
end
|
Class Method Details
.clean_tmps! ⇒ Object
29
30
31
32
|
# File 'lib/tck/lambdas/aws_function.rb', line 29
def self.clean_tmps!
FileUtils.mkdir_p tmpdir
FileUtils.rm_rf Dir.glob("#{tmpdir}/*")
end
|
.tmpdir ⇒ Object
11
12
13
|
# File 'lib/tck/lambdas/aws_function.rb', line 11
def self.tmpdir
@tmpdir ||= Dir.tmpdir + "/tck-lambdas"
end
|
.yaml ⇒ Object
15
16
17
18
19
20
21
22
23
24
25
26
27
|
# 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
|
Instance Method Details
#dir ⇒ Object
53
54
55
|
# File 'lib/tck/lambdas/aws_function.rb', line 53
def dir
@dir ||= "lambdas/#{name}"
end
|
#function_name ⇒ Object
40
41
42
|
# File 'lib/tck/lambdas/aws_function.rb', line 40
def function_name
@conf['function-name'] || name
end
|
#invoke_events_in_directory(event_type) ⇒ Object
65
66
67
68
69
70
71
72
|
# 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) ⇒ Object
74
75
76
77
78
79
80
|
# 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
|
#test_function_name ⇒ Object
44
45
46
|
# File 'lib/tck/lambdas/aws_function.rb', line 44
def test_function_name
"#{@conf['function-name']}_test"
end
|
#tmpdir ⇒ Object
57
58
59
|
# File 'lib/tck/lambdas/aws_function.rb', line 57
def tmpdir
self.class.tmpdir
end
|
#yaml ⇒ Object
82
83
84
|
# File 'lib/tck/lambdas/aws_function.rb', line 82
def yaml
self.class.yaml
end
|
#zip_file ⇒ Object
61
62
63
|
# File 'lib/tck/lambdas/aws_function.rb', line 61
def zip_file
@zip_file ||= "#{Dir.pwd}/#{dir}/#{function_name}.zip"
end
|