Class: Tree::TreeGenerator
- Inherits:
-
Rails::Generators::NamedBase
- Object
- Rails::Generators::NamedBase
- Tree::TreeGenerator
- Defined in:
- lib/generators/tree/tree_generator.rb
Instance Method Summary collapse
- #add_acts_as_tree_to_model ⇒ Object
- #add_resources_to_routes ⇒ Object
- #controller_template ⇒ Object
- #create_initializer ⇒ Object
- #migration ⇒ Object
- #view_templates ⇒ Object
Instance Method Details
#add_acts_as_tree_to_model ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/generators/tree/tree_generator.rb', line 15 def add_acts_as_tree_to_model if behavior.to_s == "invoke" inject_into_file "app/models/#{file_name}.rb", :after=>"ActiveRecord::Base\n" do <<-'TREE' acts_as_tree TREE end end end |
#add_resources_to_routes ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/generators/tree/tree_generator.rb', line 37 def add_resources_to_routes if behavior.to_s == "invoke" inject_into_file "config/routes.rb", :after=>"Rails.application.routes.draw do\n" do " resources :#{file_name.pluralize} " end end end |
#controller_template ⇒ Object
24 25 26 |
# File 'lib/generators/tree/tree_generator.rb', line 24 def controller_template template "controller.rb", "app/controllers/#{file_name.pluralize}_controller.rb" end |
#create_initializer ⇒ Object
5 6 7 |
# File 'lib/generators/tree/tree_generator.rb', line 5 def create_initializer copy_file "init.rb", init_file unless File.file? init_file end |
#migration ⇒ Object
9 10 11 12 13 |
# File 'lib/generators/tree/tree_generator.rb', line 9 def migration args.unshift('title:string') @args = args Rails::Generators.invoke('model', [file_name, args, '-s'], {:behavior=>behavior}) end |
#view_templates ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/generators/tree/tree_generator.rb', line 28 def view_templates template "views/index.html.erb", "app/views/#{file_name.pluralize}/index.html.erb" template "views/show.html.erb", "app/views/#{file_name.pluralize}/show.html.erb" template "views/edit.html.erb", "app/views/#{file_name.pluralize}/edit.html.erb" template "views/new.html.erb", "app/views/#{file_name.pluralize}/new.html.erb" template "views/_list.html.erb", "app/views/#{file_name.pluralize}/_list.html.erb" template "views/_form.html.erb", "app/views/#{file_name.pluralize}/_form.html.erb" end |