Module: Adhoq::ApplicationHelper

Defined in:
app/helpers/adhoq/application_helper.rb

Instance Method Summary collapse

Instance Method Details

#human(klass, attr = nil) ⇒ Object



3
4
5
6
7
8
9
# File 'app/helpers/adhoq/application_helper.rb', line 3

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

#icon_fa(name, additional_classes = []) ⇒ Object



11
12
13
# File 'app/helpers/adhoq/application_helper.rb', line 11

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

#query_friendly_name(query) ⇒ Object

TODO extract into presenter



22
23
24
# File 'app/helpers/adhoq/application_helper.rb', line 22

def query_friendly_name(query)
  "Query: #{query.name}"
end

#query_parameter_field(name) ⇒ Object



30
31
32
# File 'app/helpers/adhoq/application_helper.rb', line 30

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

#schema_versionObject



15
16
17
18
19
# File 'app/helpers/adhoq/application_helper.rb', line 15

def schema_version
  connection = Adhoq::Executor::ConnectionWrapper.new
  result = connection.select("SELECT MAX(version) AS current_version FROM #{ActiveRecord::SchemaMigration.table_name}")
  result.rows.first.first
end

#table_order_key(ar_class) ⇒ Object



26
27
28
# File 'app/helpers/adhoq/application_helper.rb', line 26

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