Created
June 10, 2012 20:18
-
-
Save bil-bas/2907195 to your computer and use it in GitHub Desktop.
generator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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