Sha256: 7002e30b0b674b07599a8d8b83795073c1e06d612fecb918383530325b074fa8

Contents?: true

Size: 1.02 KB

Versions: 1

Compression:

Stored size: 1.02 KB

Contents

# frozen_string_literal: true

require 'rails/generators'

module HasStates
  class InstallGenerator < Rails::Generators::Base
    source_root File.expand_path('templates', __dir__)

    TEMPLATES = [
      {
        source: 'create_has_states_states.rb.erb',
        destination: "db/migrate/%s_create_has_states_states.rb"
      },
      {
        source: 'create_indexes_on_has_states_states.rb.erb',
        destination: "db/migrate/%s_create_indexes_on_has_states_states.rb"
      },
      {
        source: 'initializer.rb.erb',
        destination: "config/initializers/has_states.rb"
      }
    ].freeze

    def install
      puts 'Installing HasStates...'

      TEMPLATES.each do |template| 
        make_template(**template)
      end

      puts 'HasStates installed successfully!'
    end

    private 

    def make_template(source:, destination:)
      timestamp = Time.now.utc.strftime('%Y%m%d%H%M%S')
      destination = destination % timestamp if destination.include?('%s')

      template(source, destination)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
stateful_models-0.0.3 lib/generators/has_states/install/install_generator.rb