Module: Adhoq::ApplicationHelper
- Defined in:
- app/helpers/adhoq/application_helper.rb
Instance Method Summary collapse
- #human(klass, attr = nil) ⇒ Object
- #icon_fa(name, additional_classes = []) ⇒ Object
-
#query_friendly_name(query) ⇒ Object
TODO extract into presenter.
- #query_parameter_field(name) ⇒ Object
- #schema_version ⇒ Object
- #table_order_key(ar_class) ⇒ Object
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
27 28 29 |
# File 'app/helpers/adhoq/application_helper.rb', line 27 def query_friendly_name(query) "Query: #{query.name}" end |
#query_parameter_field(name) ⇒ Object
35 36 37 |
# File 'app/helpers/adhoq/application_helper.rb', line 35 def query_parameter_field(name) text_field_tag "parameters[#{name}]", nil, class: "form-control" end |
#schema_version ⇒ Object
15 16 17 18 19 20 21 22 23 24 |
# File 'app/helpers/adhoq/application_helper.rb', line 15 def schema_version connection = Adhoq::Executor::ConnectionWrapper.new table = if ActiveRecord::SchemaMigration.respond_to?(:table_name) ActiveRecord::SchemaMigration.table_name # Rails <= 7.0 else "schema_migrations" # Rails 7.1+ (instance-based API) end result = connection.select("SELECT MAX(version) AS current_version FROM #{table}") result.rows.first.first end |
#table_order_key(ar_class) ⇒ Object
31 32 33 |
# File 'app/helpers/adhoq/application_helper.rb', line 31 def table_order_key(ar_class) (ar_class.primary_key || ar_class.columns.first.name).to_sym end |