Class: Kitno::KillingInTheNamespaceOf

Inherits:
Object
  • Object
show all
Defined in:
lib/kitno.rb

Constant Summary collapse

CLASS_EXPRESSION =
/^class\s(?:@)?([A-Z][\w\.]*)/
REQUIRE_TEMPLATE =
"%{short_name} = require('%{path}')"

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ KillingInTheNamespaceOf

Returns a new instance of KillingInTheNamespaceOf.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/kitno.rb', line 13

def initialize(options = {})
  @namespace, @directory, @output, globals, externals = options.values_at(
    :namespace,
    :directory,
    :output,
    :globals,
    :externals
  )

  @class_map = {}
  @files = []

  @globals = globals && globals.length > 0 ? parse_mappings(globals) : {}
  @externals = externals && externals.length > 0 ? parse_mappings(externals) : {}

  @dependency_expression = /^(?!(\s\*|#)).*(?:new|extends|=|\:)\s(#{Regexp.escape(@namespace)}[\w\.]*)/
end

Instance Method Details

#enumerateObject



48
49
50
51
52
# File 'lib/kitno.rb', line 48

def enumerate
  enumerate_files

  @class_map
end

#runObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/kitno.rb', line 31

def run
  enumerate_files

  @class_map.each_value do |descriptor|
    path, output_path = descriptor[:path]

    require_dependencies!(path, descriptor[:dependencies])

    if @output
      output_path = Pathname.new(path).sub(@directory, @output)
      FileUtils.mkdir_p output_path.dirname.to_s
    end

    FileUtils.mv "#{path}.module", output_path.to_s
  end
end