Class: BlacklightUserGeneratedContentGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- BlacklightUserGeneratedContentGenerator
- Includes:
- Rails::Generators::Migration
- Defined in:
- lib/generators/blacklight_user_generated_content/blacklight_user_generated_content_generator.rb
Class Method Summary collapse
Instance Method Summary collapse
- #add_comment_mixin ⇒ Object
- #add_document_mixin ⇒ Object
- #generate_acts_as_commentable_migrations ⇒ Object
- #generate_acts_as_taggable_migrations ⇒ Object
- #generate_cancan_ability ⇒ Object
- #inject_comments_roles ⇒ Object
- #update_taggable_id_to_string_migration ⇒ Object
Class Method Details
.next_migration_number(dirname) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/generators/blacklight_user_generated_content/blacklight_user_generated_content_generator.rb', line 11 def self.next_migration_number(dirname) if ActiveRecord::Base. Time.now.utc.strftime("%Y%m%d%H%M%S") else "%.3d" % (current_migration_number(dirname) + 1) end end |
Instance Method Details
#add_comment_mixin ⇒ Object
50 51 52 53 54 |
# File 'lib/generators/blacklight_user_generated_content/blacklight_user_generated_content_generator.rb', line 50 def add_comment_mixin inject_into_file "app/models/comment.rb", :after => "include ActsAsCommentable::Comment" do "\ninclude BlacklightUserGeneratedContent::Comment" end end |
#add_document_mixin ⇒ Object
56 57 58 59 60 61 62 |
# File 'lib/generators/blacklight_user_generated_content/blacklight_user_generated_content_generator.rb', line 56 def add_document_mixin inject_into_file "app/models/solr_document.rb", :after => "include Blacklight::Solr::Document" do "\ninclude BlacklightUserGeneratedContent::Document\n" + "include BlacklightUserGeneratedContent::Commentable\n" + "include BlacklightUserGeneratedContent::Taggable\n" end end |
#generate_acts_as_commentable_migrations ⇒ Object
46 47 48 |
# File 'lib/generators/blacklight_user_generated_content/blacklight_user_generated_content_generator.rb', line 46 def generate_acts_as_commentable_migrations generate "comment" end |
#generate_acts_as_taggable_migrations ⇒ Object
38 39 40 |
# File 'lib/generators/blacklight_user_generated_content/blacklight_user_generated_content_generator.rb', line 38 def generate_acts_as_taggable_migrations generate "acts_as_taggable_on:migration" end |
#generate_cancan_ability ⇒ Object
21 22 23 |
# File 'lib/generators/blacklight_user_generated_content/blacklight_user_generated_content_generator.rb', line 21 def generate_cancan_ability generate "cancan:ability" end |
#inject_comments_roles ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/generators/blacklight_user_generated_content/blacklight_user_generated_content_generator.rb', line 25 def inject_comments_roles inject_into_file "app/models/ability.rb", :after => "def initialize(user)" do <<-EOF user ||= User.new can :read, Comment can :create, Comment can :manage, Comment, :user_id => user.id EOF end end |
#update_taggable_id_to_string_migration ⇒ Object
42 43 44 |
# File 'lib/generators/blacklight_user_generated_content/blacklight_user_generated_content_generator.rb', line 42 def update_taggable_id_to_string_migration migration_template 'alter_taggable_id_to_string.rb', 'db/migrate/alter_taggable_id_to_string.rb' end |