Class: Iota::CLI::Create

Inherits:
Object
  • Object
show all
Defined in:
lib/iota/cli/create.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options, function_name, thor) ⇒ Create

Returns a new instance of Create.



5
6
7
8
9
10
11
# File 'lib/iota/cli/create.rb', line 5

def initialize(options, function_name, thor)
  @options = options
  @function_name = function_name
  @thor = thor
  @path = options[:path] || File.join('.', function_name)
  @runtime = options[:runtime]
end

Instance Attribute Details

#function_nameObject (readonly)

Returns the value of attribute function_name.



3
4
5
# File 'lib/iota/cli/create.rb', line 3

def function_name
  @function_name
end

#optionsObject (readonly)

Returns the value of attribute options.



3
4
5
# File 'lib/iota/cli/create.rb', line 3

def options
  @options
end

#pathObject (readonly)

Returns the value of attribute path.



3
4
5
# File 'lib/iota/cli/create.rb', line 3

def path
  @path
end

#runtimeObject (readonly)

Returns the value of attribute runtime.



3
4
5
# File 'lib/iota/cli/create.rb', line 3

def runtime
  @runtime
end

#thorObject (readonly)

Returns the value of attribute thor.



3
4
5
# File 'lib/iota/cli/create.rb', line 3

def thor
  @thor
end

Instance Method Details

#runObject



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

def run
  if Dir.exist?(path)
    thor.say("Directory '#{path}' already exists.", :red)
    return
  end

  unless Iota::Function::DEFAULT_HANDLER.has_key?(runtime)
    thor.say("Please specify valid runtime. (%s)" %
             Iota::Function::DEFAULT_HANDLER.keys.to_s)
    return
  end

  function = Iota::Function.new(function_name, path)
  thor.say("Creating function at directory #{path}.", :yellow)
  function.create_local(runtime)
  thor.say("Done.", :blue)

  if function.exists?
    thor.say("Note: Function #{function_name} already exists in remote. \\
            Please be careful to deploy it to remote.", :yellow)
  end
end