Skip to content

Instantly share code, notes, and snippets.

@bil-bas
Created June 10, 2012 20:18
Show Gist options
  • Save bil-bas/2907195 to your computer and use it in GitHub Desktop.
Save bil-bas/2907195 to your computer and use it in GitHub Desktop.
generator
require 'thor'
require 'thor/actions'
class App < Thor
include Thor::Actions
end
@run = App.new
def block_given_action(action)
@run.inject_into_class @file_name, @class_name, action
end
def index_action
block_given_action "index#{@inject}\n"
end
def show_action
block_given_action "show#{@inject}\n"
end
def controller(file_name, reverse, &block)
@file_name = file_name
@class_name = "MyClass"
@run.create_file file_name, "class #{@class_name}\nend", :force => true
actions = block.call
actions.reverse! if reverse
actions.each(&:call)
end
#template
controller 'test.rb' do
[
->{ index_action },
->{ show_action },
]
end
#return
# class MyClass
# show
# index
# end
# # want
# class MyClass
# index
# show
# end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment