Module: Koi::Helpers::AttributeHelpers

Extended by:
ActiveSupport::Concern
Included in:
AdminControllerGenerator, AdminRouteGenerator, AdminViewsGenerator
Defined in:
lib/generators/koi/helpers/attribute_helpers.rb

Defined Under Namespace

Classes: IntrospectedAttribute

Instance Method Summary collapse

Instance Method Details

#collection_attribute_for(attribute) ⇒ Object



60
61
62
# File 'lib/generators/koi/helpers/attribute_helpers.rb', line 60

def collection_attribute_for(attribute)
  AttributeTypes.for(attribute).collection_attribute
end

#default_sort_attributeObject



72
73
74
75
76
77
78
79
80
# File 'lib/generators/koi/helpers/attribute_helpers.rb', line 72

def default_sort_attribute
  if orderable?
    :ordinal
  elsif (attribute = attributes.find { |attr| attr.type == :string })
    attribute.name
  else
    attributes.first&.name
  end
end

#govuk_input_for(attribute) ⇒ Object



48
49
50
# File 'lib/generators/koi/helpers/attribute_helpers.rb', line 48

def govuk_input_for(attribute)
  AttributeTypes.for(attribute).govuk_input
end

#index_attribute_for(attribute) ⇒ Object



52
53
54
# File 'lib/generators/koi/helpers/attribute_helpers.rb', line 52

def index_attribute_for(attribute)
  AttributeTypes.for(attribute).index_row
end

#index_attributesObject



64
65
66
# File 'lib/generators/koi/helpers/attribute_helpers.rb', line 64

def index_attributes
  attributes.select { |attribute| index_attribute_for(attribute).present? }
end

#show_attribute_for(attribute) ⇒ Object



56
57
58
# File 'lib/generators/koi/helpers/attribute_helpers.rb', line 56

def show_attribute_for(attribute)
  AttributeTypes.for(attribute).show_row
end

#show_attributesObject



68
69
70
# File 'lib/generators/koi/helpers/attribute_helpers.rb', line 68

def show_attributes
  attributes.select { |attribute| show_attribute_for(attribute).present? }
end