Sha256: fa6ab71179e21dbdffe69fa5e78bee284e8e89cfc2a36b2d3fff9c3ada2e93a7

Contents?: true

Size: 993 Bytes

Versions: 1

Compression:

Stored size: 993 Bytes

Contents

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?
      ActiveRecord::Base.configurations[Rails.env].
        try(:[], "adapter").try(:match, /mysql/)
    end

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
statesman-3.0.0 lib/generators/statesman/generator_helpers.rb