Class: ModuleGenerator

Inherits:
Rails::Generators::NamedBase
  • Object
show all
Defined in:
lib/generators/module/module_generator.rb

Instance Method Summary collapse

Instance Method Details

#create_module_fileObject

source_root File.expand_path(‘../templates’, __FILE__)



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/generators/module/module_generator.rb', line 4

def create_module_file
    
    name = file_name.downcase.gsub(/\s|-/, '_')
    param = class_path
    param.map! {|item| item.downcase.gsub(/\s|-/, '_')}
    
    path = File.join('app/modules', *param)
    
    scope = []
    text = ""
    param.map! {|item|
        item = item.camelcase
        scope << item
        text += "module #{scope.join('::')}; end\n"
        item
    }
    param << name.camelcase
    scope = param.join('::')
    
    
    create_file File.join(path, "#{name}.rb") do            
        text += <<-FILE


class #{scope}
include ::Orchestrator::Constants  # On, Off and other useful constants
include ::Orchestrator::Transcoder # binary, hex and string helper methods
# For stream tokenization use ::UV::BufferedTokenizer or ::UV::AbstractTokenizer

def on_load
    # module has been started
end

def on_unload
    # module has been stopped
end

# Called when class updated at runtime
def on_update
end
end

        FILE
        
        text
    end
    
end