Class: QrcodeGenerator::Initer

Inherits:
Object
  • Object
show all
Defined in:
lib/qrcode-generator/initer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(workspace) ⇒ Initer

Returns a new instance of Initer.



11
12
13
# File 'lib/qrcode-generator/initer.rb', line 11

def initialize(workspace)
  @workspace = workspace
end

Instance Attribute Details

#workspaceObject (readonly)

Returns the value of attribute workspace.



9
10
11
# File 'lib/qrcode-generator/initer.rb', line 9

def workspace
  @workspace
end

Instance Method Details

#initObject



15
16
17
18
19
20
21
22
# File 'lib/qrcode-generator/initer.rb', line 15

def init
  if !workspace_empty?
    puts "ERROR: Count not init, because current folder is not empty"
    return
  end

  init_workspace
end

#init_workspaceObject

copy files into workspace



36
37
38
39
40
# File 'lib/qrcode-generator/initer.rb', line 36

def init_workspace
  source = File.expand_path("../workspace", __dir__)

  FileUtils.cp_r("#{source}/.", workspace)
end

#workspace_empty?Boolean

Returns:

  • (Boolean)


24
25
26
27
28
29
30
31
32
33
# File 'lib/qrcode-generator/initer.rb', line 24

def workspace_empty?
  total_size = 0

  Find.find(workspace) do |path|
    next if path == workspace or File.basename(path)[0] == ?.
    total_size += 1
  end

  total_size == 0
end