Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
extracted 'expose_as' controller helper into SingleControllerInherita…
…nce module
- Loading branch information
Showing
6 changed files
with
36 additions
and
34 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
module SingleControllerInheritance | ||
def self.included(base) | ||
base.extend ClassMethods | ||
end | ||
|
||
module ClassMethods | ||
def expose_as(*types, &block) | ||
options = types.extract_options! | ||
namespace = options[:namespace] | ||
|
||
types.each do |child| | ||
class_name = namespace.to_s + child.to_s.titleize + 'Controller' | ||
controller = Class.new(self) do | ||
block[child] if block_given? | ||
end | ||
|
||
logger.info "=> Generating new %s subclass: %s" % [child, class_name] | ||
|
||
scope = namespace ? namespace.constantize : Object | ||
scope.const_set(class_name, controller) | ||
end | ||
end | ||
end | ||
end |
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
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