lib/generators/repres/dosser/platform/platform_generator.rb in repres-dosser-1.6.1 vs lib/generators/repres/dosser/platform/platform_generator.rb in repres-dosser-1.6.2

- old
+ new

@@ -9,75 +9,41 @@ def produce @platform_name = file_name.downcase @version_number = options['version'].to_i + bind_options generate_controller generate_route end - def define_namespace(content) - content.gsub! /PlatformModuleName/, platform_module_name - content.gsub! /VersionModuleName/, version_module_name - content.gsub! /platform_name/, platform_name - content.gsub! /version_name/, version_name - content.gsub! /version_number/, version_number.to_s - content + def bind_options + @platform_module_name = @platform_name.camelize + @version_module_name = "V#{@version_number}" + @version_name = "v#{@version_number}" end # controller # # app/controllers/platform/version/presentation_controller.rb # app/controllers/platform/version/portals_controller.rb # def generate_controller - copy_file('app/controllers/presentation_controller.rb', "app/controllers/#{platform_name}/dosser/#{version_name}/presentation_controller.rb") { |content| define_namespace content } - copy_file('app/controllers/portals_controller.rb', "app/controllers/#{platform_name}/dosser/#{version_name}/portals_controller.rb" ) { |content| define_namespace content } + template 'controllers/portals_controller.rb', "app/controllers/#{@platform_name}/dosser/#{@version_name}/portals_controller.rb" + template 'controllers/presentation_controller.rb', "app/controllers/#{@platform_name}/dosser/#{@version_name}/presentation_controller.rb" end # route # # config/routes.rb # def generate_route - source = File.expand_path find_in_source_paths('config/routes.rb') - File.open(source, 'rb') { |f| route define_namespace(f.read.to_s.strip) } + source = File.expand_path find_in_source_paths('routes.rb') + content = ERB.new(File.binread(source).strip, nil, '-', "@output_buffer").result instance_eval('binding') + route content end - # Administration - def platform_module_name - @platform_name.camelize - end - - # administration - def platform_name - @platform_name - end - - # Administration::V1 - def platform_version_module_name - "#{platform_module_name}::Dosser::#{version_module_name}" - end - - # V1 - def version_module_name - "V#{version_number}" - end - - # v1 - def version_name - "v#{version_number}" - end - - # 1 - def version_number - @version_number - end - - private :define_namespace, - :generate_controller, :generate_route, - :platform_module_name, :platform_name, :platform_version_module_name, - :version_module_name, :version_name, :version_number + private :bind_options, :generate_controller, :generate_route end