Class: Streamline::Generators::Stores::ActiveRecordGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Includes:
Rails::Generators::Migration
Defined in:
lib/generators/streamline/stores/active_record_generator.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.next_migration_numberObject



9
10
11
# File 'lib/generators/streamline/stores/active_record_generator.rb', line 9

def self.next_migration_number(*)
  Time.now.utc.strftime('%Y%m%d%H%M%S')
end

Instance Method Details

#copy_migrationsObject



13
14
15
16
# File 'lib/generators/streamline/stores/active_record_generator.rb', line 13

def copy_migrations
  migration_template 'create_events.rb',
                     'db/migrate/create_streamline_events.rb'
end

#copy_modelsObject



18
19
20
# File 'lib/generators/streamline/stores/active_record_generator.rb', line 18

def copy_models
  template 'event.rb', 'app/models/streamline/event.rb'
end

#jsonb?Boolean

Returns:

  • (Boolean)


22
23
24
25
26
27
28
29
# File 'lib/generators/streamline/stores/active_record_generator.rb', line 22

def jsonb?
  return false unless postgresql?

  ActiveRecord::Base
    .connection
    .execute('SELECT version();')[0]['version']
    .start_with?('PostgreSQL 9.4')
end

#postgresql?Boolean

Returns:

  • (Boolean)


31
32
33
34
# File 'lib/generators/streamline/stores/active_record_generator.rb', line 31

def postgresql?
  config = ActiveRecord::Base.configurations[Rails.env]
  config && config['adapter'] == 'postgresql'
end