class Patriarch::Generators::BehaviourGenerator
Public Instance Methods
customize_basic_files()
click to toggle source
# File lib/generators/patriarch/behaviour_generator.rb, line 28 def customize_basic_files template "empty_behaviour_module.rb", "lib/patriarch/behaviours/#{behaviour.underscore.downcase}.rb" template "empty_service_module.rb", "lib/patriarch/services/#{behaviour.underscore.downcase}.rb" template "tools_methods.rb", "lib/patriarch/behaviours/#{behaviour.underscore.downcase}/tools_methods.rb" end
ensure_autoload()
click to toggle source
# File lib/generators/patriarch/behaviour_generator.rb, line 34 def ensure_autoload # Autoload declaration insertion for services insert_into_file "lib/patriarch/services.rb", :after => " module Services\n" do " autoload :#{class_name}, 'patriarch/services/#{behaviour.underscore.downcase}.rb'\n" end insert_into_file "lib/patriarch/services.rb", :after => " module Services\n" do " autoload :#{undo_class_name}, 'patriarch/services/#{behaviour.underscore.downcase}.rb'\n" end # Autoload declaration insertion for behaviours (no undo needed ...) insert_into_file "lib/patriarch/behaviours.rb", :after => " module Behaviours\n" do " autoload :#{class_name}, 'patriarch/behaviours/#{behaviour.underscore.downcase}.rb'\n" end # load File.expand_path('lib/patriarch/behaviours.rb', __FILE__) end
fail_if_bad_syntax()
click to toggle source
# File lib/generators/patriarch/behaviour_generator.rb, line 16 def fail_if_bad_syntax if behaviour_type != "bipartite" && behaviour_type != "tripartite" # Pleasedon't, qualify an exception here raise Exception, "bad syntax behaviour_type must be bipartite or tripartite" end end
generate_services()
click to toggle source
# File lib/generators/patriarch/behaviour_generator.rb, line 52 def generate_services create_services(behaviour,behaviour_type) # implémenter un switch ici, plus zoli ... self.class.send(:define_method,:class_name) do Patriarch.undo(behaviour).classify end create_undo_services(behaviour,behaviour_type) self.class.send(:define_method,:class_name) do behaviour.classify end end
init_directories_for_behaviour()
click to toggle source
# File lib/generators/patriarch/behaviour_generator.rb, line 23 def init_directories_for_behaviour empty_directory "lib/patriarch/services/#{behaviour.underscore.downcase}" empty_directory "lib/patriarch/services/#{Patriarch.undo(behaviour.underscore.downcase)}" end
Private Instance Methods
class_name()
click to toggle source
# File lib/generators/patriarch/behaviour_generator.rb, line 65 def class_name behaviour.classify end
create_services(behaviour,behaviour_type)
click to toggle source
# File lib/generators/patriarch/behaviour_generator.rb, line 73 def create_services(behaviour,behaviour_type) behaviour_str = behaviour.underscore.downcase template "authorization_service.rb", "lib/patriarch/services/#{behaviour_str}/authorization_service.rb" template "before_manager_service.rb", "lib/patriarch/services/#{behaviour_str}/before_manager_service.rb" template "before_service.rb", "lib/patriarch/services/#{behaviour_str}/before_service.rb" if behaviour_type == "tripartite" template "service-tripartite.rb", "lib/patriarch/services/#{behaviour_str}/service.rb" template "manager_service-tripartite.rb", "lib/patriarch/services/#{behaviour_str}/manager_service.rb" elsif behaviour_type == "bipartite" template "service.rb", "lib/patriarch/services/#{behaviour_str}/service.rb" template "manager_service.rb", "lib/patriarch/services/#{behaviour_str}/manager_service.rb" end template "after_manager_service.rb", "lib/patriarch/services/#{behaviour_str}/after_manager_service.rb" template "after_service.rb", "lib/patriarch/services/#{behaviour_str}/after_service.rb" end
create_undo_services(behaviour,behaviour_type)
click to toggle source
# File lib/generators/patriarch/behaviour_generator.rb, line 94 def create_undo_services(behaviour,behaviour_type) undo_behaviour_str = Patriarch.undo(behaviour).underscore.downcase template "authorization_service.rb", "lib/patriarch/services/#{undo_behaviour_str}/authorization_service.rb" template "before_manager_service.rb", "lib/patriarch/services/#{undo_behaviour_str}/before_manager_service.rb" template "before_service.rb", "lib/patriarch/services/#{undo_behaviour_str}/before_service.rb" # Please don't go another generator if necessary or do other functions if behaviour_type == "tripartite" template "undo_service-tripartite.rb", "lib/patriarch/services/#{undo_behaviour_str}/service.rb" template "manager_service-tripartite.rb", "lib/patriarch/services/#{undo_behaviour_str}/manager_service.rb" elsif behaviour_type == "bipartite" template "undo_service.rb", "lib/patriarch/services/#{undo_behaviour_str}/service.rb" template "manager_service.rb", "lib/patriarch/services/#{undo_behaviour_str}/manager_service.rb" end template "after_manager_service.rb", "lib/patriarch/services/#{undo_behaviour_str}/after_manager_service.rb" template "after_service.rb", "lib/patriarch/services/#{undo_behaviour_str}/after_service.rb" end
undo_class_name()
click to toggle source
# File lib/generators/patriarch/behaviour_generator.rb, line 69 def undo_class_name Patriarch.undo(behaviour).classify end