Permalink
Browse files

generators added

  • Loading branch information...
1 parent 00e74a1 commit 5dbf711ff878712b82351386d3c97424dcc00655 @kristianmandrup committed Aug 17, 2012
@@ -21,3 +21,7 @@ def method_missing(meth, *args, &block)
end
end
+module Assistants
+ Assistant = Controll::Assistant
+ DelegateAssistant = Controll::DelegateAssistant
+end
@@ -0,0 +1,27 @@
+module Controll
+ module Generators
+ class AssistantGenerator < ::Rails::Generators::NamedBase
+ desc 'Generates an Assitant'
+
+ class_option :delegate, type: :boolean, default: false
+
+ def main_flow
+ template "assistant.tt", "app/controll/assistants/#{file_name}.rb"
+ end
+
+ protected
+
+ def delegate?
+ options[:delegate]
+ end
+
+ def parent_class
+ name.include?('::') ? "::Controll::#{parent_class_name}" : parent_class_name
+ end
+
+ def parent_class_name
+ delegate? 'DelegateAssistant' : 'Assistant'
+ end
+ end
+ end
+end
@@ -0,0 +1,23 @@
+module Controll
+ module Generators
+ class ExecutorGenerator < ::Rails::Generators::NamedBase
+ desc 'Generates an Executor'
+
+ class_option :type, default: 'base', desc: 'The type of executor'
+
+ def main_flow
+ template 'executor.tt', "app/controll/executors/#{file_name}.rb"
+ end
+
+ protected
+
+ def parent_class
+ name.include?('::') ? "::Controll::Executor::#{parent_class_name}" : parent_class_name
+ end
+
+ def parent_class_name
+ (options[:type] || 'base').camelize
+ end
+ end
+ end
+end
@@ -0,0 +1,21 @@
+module Controll
+ module Generators
+ class FlowHandlerGenerator < ::Rails::Generators::NamedBase
+ desc 'Generates a FlowHandler'
+
+ def main_flow
+ template 'flow_handler.tt', "app/controll/flow_handlers/#{file_name}.rb"
+ end
+
+ protected
+
+ def parent_class
+ name.include?('::') ? "::Controll::FlowHandler::#{parent_class_name}" : parent_class_name
+ end
+
+ def parent_class_name
+ 'Control'
+ end
+ end
+ end
+end
@@ -0,0 +1,21 @@
+module Controll
+ module Generators
+ class NotifierGenerator < ::Rails::Generators::NamedBase
+ desc 'Generates a Notifier'
+
+ def main_flow
+ template 'notifier.tt', "app/controll/notifiers/#{file_name}.rb"
+ end
+
+ protected
+
+ def parent_class
+ name.include?('::') ? "::Controll::Notify::#{parent_class_name}" : parent_class_name
+ end
+
+ def parent_class_name
+ 'Typed'
+ end
+ end
+ end
+end
@@ -1,23 +1,37 @@
module Controll
- class SetupGenerator < Rails::Generator::Base
- desc 'Sets up a Rails 3 prooject with a folder structure in app for controll artifacts'
+ module Generators
+ class SetupGenerator < ::Rails::Generators::Base
+ desc 'Sets up a Rails 3 prooject with a folder structure in app for controll artifacts'
- argument :folders, type: :array, required: false, desc: 'creates specific folders for controll artifacts'
+ argument :folders, type: :array, required: false, desc: 'creates specific folders for controll artifacts'
- def main_flow
- empty_directory "app/controll"
- inside "app/controll" do
- create_folders.each do |folder|
- empty_directory folder
+ def main_flow
+ empty_directory "app/controll"
+ inside "app/controll" do
+ create_folders.each do |folder|
+ empty_directory folder
+ end
end
end
- end
- protected
+ protected
+
+ def create_folders
+ return mapper_folders unless folders.empty?
+ valid_folders
+ end
+
+ def mapper_folders
+ @mapper_folders ||= folders.map {|f| f.to_s.underscore }.select{|f| valid_artifact? f }
+ end
+
+ def valid_folder? folder
+ valid_folders.include? folder.to_s.underscore
+ end
- def create_folders
- return folders unless folders.empty?
- %w{executors flow_handlers notifiers commanders}
+ def valid_folders
+ %w{executors flow_handlers notifiers commanders assistants}
+ end
end
end
end
@@ -0,0 +1,10 @@
+module Assistants
+ class <%= class_name %> < <%= parent_class %>
+ # public methods here
+ # def do_stuff
+ # ... if current_user
+ # end
+
+ # controller_methods :current_user
+ end
+end
@@ -0,0 +1,15 @@
+module Commanders
+ class <%= class_name %> < <%= parent_class %>
+ # create basic command methods
+ # command_methods :cancel_commit, :create_account, :signout
+
+ # create custom command method with custom argument hash
+
+ # command_method :sign_out do
+ # end
+
+ # controller delegations
+ # controller_methods :auth_hash, :user_id
+ end
+end
+```
@@ -0,0 +1,14 @@
+module Executors
+ class <%= class_name %> < <%= parent_class %>
+ def execute
+ # creates an error notification named :error
+ error and return unless valid_params?
+
+ # creates an error notification named :auth_invalid
+ # error(:auth_invalid) and return unless auth_valid?
+
+ # command! :sign_in
+ # result
+ end
+ end
+end
@@ -0,0 +1,26 @@
+module FlowHandlers
+ class <%= class_name %> < <%= parent_class %>
+ fallback do
+ # event == :no_auth ? do_render(:text => omniauth.to_yaml) : fallback_action
+ end
+
+ event do
+ # Executors::Authenticator.new(controller).execute
+ end
+
+ renderer do
+ # default_path :signup_services_path
+ # events :signed_in_new_user, :signed_in
+ end
+
+ redirecter do
+ redirections :notice do
+ {
+ # signup_services_path: :signed_in_new_user
+ }
+ end
+
+ # redirections :error, signin_path: [:error, :invalid, :auth_error]
+ end
+ end
+end
@@ -0,0 +1,31 @@
+module Notifiers
+ class <%= class_name %> < <%= parent_class %>
+ handler :notice do
+ # ...
+ end
+
+ handler :error do
+ messages do
+ {
+ must_sign_in: 'You need to sign in before accessing this page!',
+
+ auth_service_error: %q{There was an error at the remote authentication service.
+You have not been signed in.},
+
+ cant_delete_current_account: 'You are currently signed in with this account!',
+ user_save_error: 'This is embarrassing! There was an error while creating your account from which we were not able to recover.',
+ }
+ end
+
+ msg :auth_error! do
+ "Error while authenticating via #{service_name}. The service did not return valid data."
+ end
+
+ msg :auth_invalid! do
+ 'Error while authenticating via {{full_route}}. The service returned invalid data for the user id.'
+ end
+ end
+ end
+end
+
+

0 comments on commit 5dbf711

Please sign in to comment.