Module: Upgrow::Generators::Helper

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



12
13
14
# File 'lib/generators/upgrow.rb', line 12

def self.included(base)
  base.extend(ClassMethods)
end

Instance Method Details

#class_nameObject



30
31
32
# File 'lib/generators/upgrow.rb', line 30

def class_name
  file_name.camelize
end

#module_namespacing(&block) ⇒ Object



34
35
36
37
38
39
# File 'lib/generators/upgrow.rb', line 34

def module_namespacing(&block)
  super do
    content = capture(&block)
    concat(namespace_content(class_path, content))
  end
end

#move_file(origin, destination) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/generators/upgrow.rb', line 16

def move_file(origin, destination)
  origin = File.expand_path(origin, destination_root)
  destination = File.expand_path(destination, destination_root)

  say_status(
    :move,
    "#{relative_to_original_destination_root(origin)} -> " +
      relative_to_original_destination_root(destination)
  )

  FileUtils.mkdir_p(File.dirname(destination))
  FileUtils.mv(origin, destination)
end

#namespace_content(namespaces, content) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
# File 'lib/generators/upgrow.rb', line 41

def namespace_content(namespaces, content)
  namespace = namespaces.shift

  content = namespace_content(namespaces, content) if namespaces.any?

  if namespace
    "module #{namespace.camelize}\n#{indent(content).chomp}\nend\n"
  else
    content
  end
end