Class: Jarbs::FunctionDefinition

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/jarbs/function_definition.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, env = 'dev') ⇒ FunctionDefinition

Returns a new instance of FunctionDefinition.



10
11
12
13
14
# File 'lib/jarbs/function_definition.rb', line 10

def initialize(name, env='dev')
  @env = env
  @name = name
  @root_path = File.join('lambdas', name)
end

Instance Attribute Details

#envObject (readonly)

Returns the value of attribute env.



7
8
9
# File 'lib/jarbs/function_definition.rb', line 7

def env
  @env
end

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/jarbs/function_definition.rb', line 7

def name
  @name
end

#root_pathObject (readonly)

Returns the value of attribute root_path.



7
8
9
# File 'lib/jarbs/function_definition.rb', line 7

def root_path
  @root_path
end

Instance Method Details

#basename(filename) ⇒ Object



54
55
56
# File 'lib/jarbs/function_definition.rb', line 54

def basename(filename)
  filename.gsub(build_path + '/', '')
end

#build_pathObject



46
47
48
# File 'lib/jarbs/function_definition.rb', line 46

def build_path
  File.join(root_path, 'dest')
end

#each_file(&block) ⇒ Object



42
43
44
# File 'lib/jarbs/function_definition.rb', line 42

def each_file(&block)
  files.each {|file| yield basename(file), File.read(file) }
end

#env_nameObject



32
33
34
# File 'lib/jarbs/function_definition.rb', line 32

def env_name
  "#{env}-#{name}"
end

#exists?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/jarbs/function_definition.rb', line 16

def exists?
  Dir.exists? root_path
end

#filesObject



36
37
38
39
40
# File 'lib/jarbs/function_definition.rb', line 36

def files
  path = File.join build_path, "**", "*"
  Dir.glob(path, File::FNM_DOTMATCH)
      .reject {|f| File.directory? f }
end

#manifestObject



24
25
26
# File 'lib/jarbs/function_definition.rb', line 24

def manifest
  @manifest ||= OpenStruct.new JSON.parse(File.read(manifest_file))
end

#manifest_fileObject



28
29
30
# File 'lib/jarbs/function_definition.rb', line 28

def manifest_file
  File.join(source_path, 'package.json')
end

#remove!Object



20
21
22
# File 'lib/jarbs/function_definition.rb', line 20

def remove!
  FileUtils.rm_r root_path
end

#source_pathObject



50
51
52
# File 'lib/jarbs/function_definition.rb', line 50

def source_path
  File.join(root_path, 'src')
end