Sha256: f38dd82828273945a2a6e4280dae881ccbe4dc5796ddf7ae815b49ec98ccced8

Contents?: true

Size: 1.35 KB

Versions: 2

Compression:

Stored size: 1.35 KB

Contents

# frozen_string_literal: true

module Statesman
  module GeneratorHelpers
    def class_name_option
      ", class_name: '#{parent}'" unless parent.underscore == parent_name
    end

    def model_file_name
      "app/models/#{klass.underscore}.rb"
    end

    def migration_class_name
      klass.gsub("::", "").pluralize
    end

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

    def parent_name
      parent.demodulize.underscore
    end

    def parent_table_name
      parent.demodulize.underscore.pluralize
    end

    def parent_id
      parent_name + "_id"
    end

    def table_name
      klass.demodulize.underscore.pluralize
    end

    def index_name(index_id)
      "index_#{table_name}_#{index_id}"
    end

    def mysql?
      configuration.try(:[], "adapter").try(:match, /mysql/)
    end

    # [] is deprecated and will be removed in 6.2
    def configuration
      if ActiveRecord::Base.configurations.respond_to?(:configs_for)
        ActiveRecord::Base.configurations.configs_for(env_name: Rails.env).first
      else
        ActiveRecord::Base.configurations[Rails.env]
      end
    end

    def database_supports_partial_indexes?
      Statesman::Adapters::ActiveRecord.database_supports_partial_indexes?
    end

    def metadata_default_value
      Utils.rails_5_or_higher? ? "{}" : "{}".inspect
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
statesman-11.0.0 lib/generators/statesman/generator_helpers.rb
statesman-10.2.3 lib/generators/statesman/generator_helpers.rb