Module: Lotus::Controller
- Includes:
- Utils::ClassAttribute
- Defined in:
- lib/lotus/controller.rb,
lib/lotus/controller/dsl.rb,
lib/lotus/controller/version.rb,
lib/lotus/controller/configuration.rb
Overview
A set of logically grouped actions
Defined Under Namespace
Modules: Dsl Classes: Configuration, UnknownFormatError
Constant Summary collapse
- VERSION =
Defines the version
'0.2.0'
Class Method Summary collapse
-
.configure(&blk) ⇒ Object
Configure the framework.
-
.dupe ⇒ Module
private
Duplicate Lotus::Controller in order to create a new separated instance of the framework.
-
.duplicate(mod, controllers = 'Controllers', &blk) ⇒ Module
Duplicate the framework and generate modules for the target application.
-
.included(base) ⇒ Object
private
Override Ruby’s hook for modules.
Class Method Details
.configure(&blk) ⇒ Object
Configure the framework. It yields the given block in the context of the configuration
68 69 70 |
# File 'lib/lotus/controller.rb', line 68 def self.configure(&blk) configuration.instance_eval(&blk) end |
.dupe ⇒ Module
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Duplicate Lotus::Controller in order to create a new separated instance of the framework.
The new instance of the framework will be completely decoupled from the original. It will inherit the configuration, but all the changes that happen after the duplication, won’t be reflected on the other copies.
117 118 119 120 121 |
# File 'lib/lotus/controller.rb', line 117 def self.dupe dup.tap do |duplicated| duplicated.configuration = configuration.duplicate end end |
.duplicate(mod, controllers = 'Controllers', &blk) ⇒ Module
Duplicate the framework and generate modules for the target application
@since 0.2.0
module MyApp::Controllers::Dashboard
include MyApp::Controller
action 'Index' do # this will inject MyApp::Action
def call(params)
# ...
end
end
end
229 230 231 232 233 234 235 236 237 238 239 240 241 242 |
# File 'lib/lotus/controller.rb', line 229 def self.duplicate(mod, controllers = 'Controllers', &blk) dupe.tap do |duplicated| mod.module_eval %{ module #{ controllers }; end } if controllers mod.module_eval %{ Action = Lotus::Action.dup } duplicated.module_eval %{ configure do action_module #{ mod }::Action end } duplicated.configure(&blk) if block_given? end end |
.included(base) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Override Ruby’s hook for modules. It includes basic Lotus::Controller modules to the given Class (or Module). It sets a copy of the framework configuration
256 257 258 259 260 261 262 263 264 265 266 |
# File 'lib/lotus/controller.rb', line 256 def self.included(base) conf = self.configuration.duplicate base.class_eval do include Dsl include Utils::ClassAttribute class_attribute :configuration self.configuration = conf end end |