Class: Patriarch::Generators::BehaviourGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/patriarch/behaviour_generator.rb

Instance Method Summary collapse

Instance Method Details

#customize_basic_filesObject



28
29
30
31
32
# 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_autoloadObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# 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_syntaxObject



16
17
18
19
20
21
# 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_servicesObject



52
53
54
55
56
57
58
59
60
61
62
# 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_behaviourObject



23
24
25
26
# 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