Added support for Rails 5.1
Andrew Kane
committed Apr 29, 2017
commit 91de924e51b9449d04df8c0f6cd401495f835f41
Showing 5
changed files with
20 additions
and 4 deletions
CHANGELOG.md
+4
-0
| @@ | @@ -1,3 +1,7 @@ |
| + | ## 1.6.0 [unreleased] |
| + | |
| + | - Added support for Rails 5.1 |
| + | |
| ## 1.5.5 | |
| - Added support for Rails API | |
generators/ahoy/stores/active_record_events_generator.rb b/lib/generators/ahoy/stores/active_record_events_generator.rb
+7
-1
| @@ | @@ -28,7 +28,7 @@ module Ahoy |
| unless @database.in?([nil, "postgresql", "postgresql-jsonb", "mysql", "sqlite"]) | |
| raise Thor::Error, "Unknown database option" | |
| end | |
| - | migration_template "active_record_events_migration.rb", "db/migrate/create_ahoy_events.rb" |
| + | migration_template "active_record_events_migration.rb", "db/migrate/create_ahoy_events.rb", migration_version: migration_version |
| end | |
| def generate_model | |
| @@ | @@ -47,6 +47,12 @@ module Ahoy |
| "postgresql" | |
| end | |
| end | |
| + | |
| + | def migration_version |
| + | if ActiveRecord::VERSION::MAJOR >= 5 |
| + | "[#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}]" |
| + | end |
| + | end |
| end | |
| end | |
| end | |
generators/ahoy/stores/active_record_visits_generator.rb b/lib/generators/ahoy/stores/active_record_visits_generator.rb
+7
-1
| @@ | @@ -27,7 +27,7 @@ module Ahoy |
| unless options["database"].in?([nil, "postgresql", "postgresql-jsonb"]) | |
| raise Thor::Error, "Unknown database option" | |
| end | |
| - | migration_template "active_record_visits_migration.rb", "db/migrate/create_visits.rb" |
| + | migration_template "active_record_visits_migration.rb", "db/migrate/create_visits.rb", migration_version: migration_version |
| end | |
| def generate_model | |
| @@ | @@ -37,6 +37,12 @@ module Ahoy |
| def create_initializer | |
| template "active_record_initializer.rb", "config/initializers/ahoy.rb" | |
| end | |
| + | |
| + | def migration_version |
| + | if ActiveRecord::VERSION::MAJOR >= 5 |
| + | "[#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}]" |
| + | end |
| + | end |
| end | |
| end | |
| end | |
generators/ahoy/stores/templates/active_record_events_migration.rb b/lib/generators/ahoy/stores/templates/active_record_events_migration.rb
+1
-1
| @@ | @@ -1,4 +1,4 @@ |
| - | class <%= migration_class_name %> < ActiveRecord::Migration |
| + | class <%= migration_class_name %> < ActiveRecord::Migration<%= migration_version %> |
| def change | |
| create_table :ahoy_events do |t| | |
| t.integer :visit_id | |
generators/ahoy/stores/templates/active_record_visits_migration.rb b/lib/generators/ahoy/stores/templates/active_record_visits_migration.rb
+1
-1
| @@ | @@ -1,4 +1,4 @@ |
| - | class <%= migration_class_name %> < ActiveRecord::Migration |
| + | class <%= migration_class_name %> < ActiveRecord::Migration<%= migration_version %> |
| def change | |
| create_table :visits do |t| | |
| t.string :visit_token | |