Module: SimpleResourceController::Controller
- Defined in:
- lib/simple_resource_controller/controller.rb,
lib/simple_resource_controller/controller/config.rb,
lib/simple_resource_controller/controller/actions.rb,
lib/simple_resource_controller/controller/implementation.rb,
lib/simple_resource_controller/controller/implementation/format/api.rb,
lib/simple_resource_controller/controller/implementation/format/html.rb
Defined Under Namespace
Modules: Actions, Config, Implementation
Constant Summary collapse
- DEPENDENCIES_MAP =
{ index: Actions::Index, show: Actions::Show, new: Actions::New, create: Actions::Create, edit: Actions::Edit, update: Actions::Update, destroy: Actions::Destroy }.freeze
- HELPER_METHODS =
[:resource, :collection].freeze
- ALL_ACTIONS_ALIAS =
:crud
Class Method Summary collapse
Class Method Details
.build(controller_class, actions) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/simple_resource_controller/controller.rb', line 21 def self.build(controller_class, actions) unless actions.include?(ALL_ACTIONS_ALIAS) raise 'Unknown action name' unless (actions - DEPENDENCIES_MAP.keys).size.zero? end loaded_modules = [Implementation] if actions.include?(ALL_ACTIONS_ALIAS) loaded_modules += DEPENDENCIES_MAP.values else loaded_modules += actions.map { |action_name| DEPENDENCIES_MAP[action_name] } end loaded_modules.uniq.each do |loaded_module| controller_class.include loaded_module end HELPER_METHODS.each do |method_name| controller_class.helper_method method_name end controller_class.respond_to :html controller_class.respond_to :json end |