Created
December 13, 2012 21:10
-
-
Save sent-hil/4279920 to your computer and use it in GitHub Desktop.
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
module Dsl | |
class Resource | |
attr_accessor :name | |
def initialize(name) | |
@name = name | |
end | |
def get | |
puts name | |
end | |
end | |
def resources(name, &blk) | |
if @current_resource | |
@previous_resource = @current_resource | |
end | |
@current_resource = Resource.new(name) | |
instance_eval(&blk) if block_given? | |
if @previous_resource | |
@current_resource = @previous_resource | |
end | |
end | |
def method_missing(name, *args, &blk) | |
if @current_resource | |
@current_resource.send(name, *args, &blk) | |
else | |
super | |
end | |
end | |
end | |
class Post | |
extend Dsl | |
resources :users do | |
get | |
resources :blogs do | |
get | |
end | |
resources :posts do | |
get | |
resources :comments do | |
get | |
end | |
end | |
get | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment