Sha256: e64ea2bde755b524aebae5c5af663e06f79ef531c4aae207a34f37f15bff3641
Contents?: true
Size: 819 Bytes
Versions: 9
Compression:
Stored size: 819 Bytes
Contents
class ControllerGenerator < Rails::Generators::NamedBase desc "Adds method 'control_me' to a Controller" def self.source_root @source_root ||= File.expand_path("../templates", __FILE__) end def add_helper_method if File.exist?(controller_file_name) inject_into_file(controller_file_name, controller_method_code, :after => after_txt) if after_txt else say "#{controller_file_name} does not exist. Please create it first before you can add a controller method to it!", :red end end protected def after_txt "#{class_name}Controller" end def controller_file_name File.join(Rails.root, "app/controllers/#{file_name}_controller.rb") end def controller_method_code %Q{ def control_me "Control me please!" end } end end
Version data entries
9 entries across 9 versions & 1 rubygems