Class: Lesli::ControllerOperator
- Inherits:
-
ApplicationLesliService
- Object
- ApplicationLesliService
- Lesli::ControllerOperator
- Defined in:
- app/operators/lesli/controller_operator.rb
Constant Summary collapse
- DEVISE_CONTROLLERS =
[ "users/registrations", "users/sessions", "users/passwords", "users/confirmations" ]
Instance Method Summary collapse
- #build ⇒ Object
-
#initialize ⇒ ControllerOperator
constructor
A new instance of ControllerOperator.
Methods inherited from ApplicationLesliService
#create, #delete, #error, #errors, #errors_as_sentence, #find, #found?, #index, #list, #result, #show, #successful?, #update
Constructor Details
#initialize ⇒ ControllerOperator
Returns a new instance of ControllerOperator.
43 44 |
# File 'app/operators/lesli/controller_operator.rb', line 43 def initialize end |
Instance Method Details
#build ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'app/operators/lesli/controller_operator.rb', line 47 def build # get all the engines, controllers and actions engines = scan_for_engine_controllers # Register descriptors and privileges for all the accounts engines.each do |engine, controllers| controllers.each do |controller_route, controller_actions| # Build a strig with the standard name of a Rails controller from the standard routes # Examples: # users converts to Users # cloud_bell/notifications converts to CloudBell::Notifications # sometimes we need a second split to deal with third level deep of controllers # Example: "Account::Currency::ExchangeRatesController" from "account/currency/exchange_rates" reference = controller_route .split('/') # split the controller path by namespace .collect(&:capitalize) # uppercase the first letter to match the class name convention of Rails .join("::") # join by ruby class separator for namespaces .split('_') # work with compound words like "exchange_rates" .collect { |x| x[0] = x[0].upcase; x } # convert ['exchange', 'rates'] to ['Exchange', 'Rates'] .join('') # joins everything in a single string name = reference.sub('::',' ') controller = Lesli::SystemController.create_with({ name: name, :engine => engine, :reference => reference }).find_or_create_by!(route: controller_route) controller_actions.each do |action_name| controller.actions.find_or_create_by!(name: action_name) end end end end |