Class: ModuleGenerator
- Inherits:
-
Rails::Generators::NamedBase
- Object
- Rails::Generators::NamedBase
- ModuleGenerator
- Defined in:
- lib/generators/module/module_generator.rb
Instance Method Summary collapse
-
#create_module_file ⇒ Object
source_root File.expand_path(‘../templates’, __FILE__).
Instance Method Details
#create_module_file ⇒ Object
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 |
# 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 type = ask("What type of module (device, service, logic) will this be?") text += <<-FILE class #{scope} < AutomateEm::#{type.downcase.camelcase} def on_load end def on_unload end def on_update end end FILE text end end |