Skip to content

Commit

Permalink
Refactoring for Lotus::Routing::Resources: remove the unnecessary cod…
Browse files Browse the repository at this point in the history
…e that can me inherited instead.
  • Loading branch information
jodosha committed Jan 10, 2014
1 parent 9fea1e7 commit 4b31c50
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 26 deletions.
25 changes: 17 additions & 8 deletions lib/lotus/routing/resource.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
require 'lotus/utils/class_attribute'
require 'lotus/routing/resource/options'
require 'lotus/routing/resource/action'

module Lotus
module Routing
class Resource
@actions = [:new, :create, :show, :edit, :update, :destroy]
include Utils::ClassAttribute

class_attribute :actions
self.actions = [:new, :create, :show, :edit, :update, :destroy]

class_attribute :action
self.action = Resource::Action

class_attribute :member
self.member = Resource::MemberAction

class_attribute :collection
self.collection = Resource::CollectionAction

def initialize(router, name, options = {}, &blk)
@router = router
Expand All @@ -16,22 +29,18 @@ def initialize(router, name, options = {}, &blk)
private
def generate(&blk)
@options.actions.each do |action|
Action.generate(@router, action, @options)
self.class.action.generate(@router, action, @options)
end

instance_eval(&blk) if block_given?
end

def self.actions
@actions
end

def member(&blk)
MemberAction.new(@router, @options.merge(prefix: @name), &blk)
self.class.member.new(@router, @options.merge(prefix: @name), &blk)
end

def collection(&blk)
CollectionAction.new(@router, @options.merge(prefix: @name), &blk)
self.class.collection.new(@router, @options.merge(prefix: @name), &blk)
end
end
end
Expand Down
22 changes: 4 additions & 18 deletions lib/lotus/routing/resources.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,10 @@
module Lotus
module Routing
class Resources < Resource
@actions = [:index, :new, :create, :show, :edit, :update, :destroy]

private
def generate(&blk)
@options.actions.each do |action|
Action.generate(@router, action, @options)
end

instance_eval(&blk) if block_given?
end

def member(&blk)
MemberAction.new(@router, @options.merge(prefix: @name), &blk)
end

def collection(&blk)
CollectionAction.new(@router, @options.merge(prefix: @name), &blk)
end
self.actions = [:index, :new, :create, :show, :edit, :update, :destroy]
self.action = Resources::Action
self.member = Resources::MemberAction
self.collection = Resources::CollectionAction
end
end
end

0 comments on commit 4b31c50

Please sign in to comment.