Class: Xaases::Aws::LambdaJs
- Inherits:
-
Object
- Object
- Xaases::Aws::LambdaJs
- Defined in:
- lib/xaases/aws/lambda_js.rb
Instance Attribute Summary collapse
-
#minify ⇒ Object
readonly
Returns the value of attribute minify.
Instance Method Summary collapse
- #dynamo_put(table, data, handler) ⇒ Object
- #export(name, content) ⇒ Object
- #header! ⇒ Object
-
#initialize(minify: true, header: false) ⇒ LambdaJs
constructor
A new instance of LambdaJs.
- #render ⇒ Object
- #res(status, content) ⇒ Object
- #use_dynamo! ⇒ Object
Constructor Details
#initialize(minify: true, header: false) ⇒ LambdaJs
Returns a new instance of LambdaJs.
7 8 9 10 11 |
# File 'lib/xaases/aws/lambda_js.rb', line 7 def initialize(minify: true, header: false) @minify = minify @js = Xaases::Js.new(minify: minify) header! if header end |
Instance Attribute Details
#minify ⇒ Object (readonly)
Returns the value of attribute minify.
5 6 7 |
# File 'lib/xaases/aws/lambda_js.rb', line 5 def minify @minify end |
Instance Method Details
#dynamo_put(table, data, handler) ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/xaases/aws/lambda_js.rb', line 36 def dynamo_put(table, data, handler) params = { 'TableName' => "'#{table}'", 'Item' => Xaases::Js.new(minify: minify).hash(data) } params_js = Xaases::Js.new(minify: minify).hash(params) @js.call 'db.put', params_js, handler end |
#export(name, content) ⇒ Object
23 24 25 26 27 28 |
# File 'lib/xaases/aws/lambda_js.rb', line 23 def export(name, content) #f = Xaases::Js::Function.new(:eve, :ctx, :cb) f = Xaases::Js::Function.new(:event, :context, :callback) f.content = content @js.export(name, f) end |
#header! ⇒ Object
13 14 15 16 17 |
# File 'lib/xaases/aws/lambda_js.rb', line 13 def header! @js.strict! @js.const(aws: "require('aws-sdk')") use_dynamo! end |
#render ⇒ Object
45 46 47 |
# File 'lib/xaases/aws/lambda_js.rb', line 45 def render @js.render end |
#res(status, content) ⇒ Object
30 31 32 33 34 |
# File 'lib/xaases/aws/lambda_js.rb', line 30 def res(status, content) #err = err ? err : 'null' body = Xaases::Js.new(minify: minify).hash('statusCode' => status, 'body' => content) @js.call :callback, 'null', body end |
#use_dynamo! ⇒ Object
19 20 21 |
# File 'lib/xaases/aws/lambda_js.rb', line 19 def use_dynamo! @js.const(db: 'new aws.DynamoDB()') end |