Class: ActiveRecord::Generators::BucketMakerGenerator
- Inherits:
-
Base
- Object
- Base
- ActiveRecord::Generators::BucketMakerGenerator
- Defined in:
- lib/generators/active_record/bucket_maker_generator.rb
Constant Summary collapse
- ACTIVE_RECORDABLE =
'bucket'
Instance Method Summary collapse
- #copy_bucket_maker_migration ⇒ Object
- #generate_model ⇒ Object
- #inject_bucket_maker_content ⇒ Object
- #inject_for_active_recordable ⇒ Object
Instance Method Details
#copy_bucket_maker_migration ⇒ Object
54 55 56 57 58 |
# File 'lib/generators/active_record/bucket_maker_generator.rb', line 54 def copy_bucket_maker_migration if behavior == :invoke && store_in == 'active_record' && active_recordable_exists? migration_template "active_recordable_migration.rb", "db/migrate/create_#{ACTIVE_RECORDABLE.pluralize}" end end |
#generate_model ⇒ Object
12 13 14 15 16 17 |
# File 'lib/generators/active_record/bucket_maker_generator.rb', line 12 def generate_model invoke "active_record:model", [name], :migration => false unless model_exists? && behavior == :invoke if store_in == 'active_record' invoke "active_record:model", [ACTIVE_RECORDABLE], :migration => false unless active_recordable_exists? && behavior == :invoke end end |
#inject_bucket_maker_content ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/generators/active_record/bucket_maker_generator.rb', line 19 def inject_bucket_maker_content contents = <<-CONTENT.strip_heredoc # Module Inclusion for BucketMaker # The options are # - BucketMaker::Models::Redisable # include #{module_name_for_include} CONTENT klass_path = if namespaced? class_name.to_s.split("::") else [class_name] end indent_depth = klass_path.size contents = contents.split("\n").map { |line| " " * indent_depth + line } .join("\n") << "\n\n" inject_into_class(model_path, klass_path.last, contents) if model_exists? inject_for_active_recordable if store_in == 'active_record' && active_recordable_exists? end |
#inject_for_active_recordable ⇒ Object
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/generators/active_record/bucket_maker_generator.rb', line 43 def inject_for_active_recordable ar_contents = <<-CONTENT.strip_heredoc # Association with the bucket belongs_to :bucketable, polymorphic: true CONTENT ar_contents = ar_contents.split("\n").map { |line| " " + line } .join("\n") << "\n\n" inject_into_class(active_recordable_path, ACTIVE_RECORDABLE.camelize, ar_contents) end |