Sha256: 82b8e5a8e784a2feb98e5bcf559f995c5d524c0ce13e91925edbd752bb3b9fae

Contents?: true

Size: 1.01 KB

Versions: 4

Compression:

Stored size: 1.01 KB

Contents

module Adhoq
  module ApplicationHelper
    def human(klass, attr = nil)
      if attr
        klass.human_attribute_name(attr)
      else
        klass.model_name.humanize
      end
    end

    def icon_fa(name, additional_classes = [])
      tag('i', class: ['fa', "fa-#{name}", *additional_classes])
    end

    def schema_version
      if defined?(ActiveRecord::SchemaMigration)
        ActiveRecord::SchemaMigration.maximum(:version)
      else
        connection = Adhoq::Executor::ConnectionWrapper.new
        result = connection.select("SELECT MAX(version) AS current_version FROM #{ActiveRecord::Migrator.schema_migrations_table_name}")
        result.rows.first.first
      end
    end

    # TODO extract into presenter
    def query_friendly_name(query)
      "Query: #{query.name}"
    end

    def table_order_key(ar_class)
      ar_class.primary_key || ar_class.columns.first.name
    end

    def query_parameter_field(name)
      text_field_tag "parameters[#{name}]", nil, class: "form-control"
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
adhoq-0.1.2 app/helpers/adhoq/application_helper.rb
adhoq-0.1.1 app/helpers/adhoq/application_helper.rb
adhoq-0.1.0 app/helpers/adhoq/application_helper.rb
adhoq-0.0.7 app/helpers/adhoq/application_helper.rb