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



66
67
68
# File 'lib/generators/koi/helpers/attribute_helpers.rb', line 66

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

#default_sort_attributeObject



78
79
80
81
82
83
84
85
86
# File 'lib/generators/koi/helpers/attribute_helpers.rb', line 78

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



54
55
56
# File 'lib/generators/koi/helpers/attribute_helpers.rb', line 54

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

#index_attribute_for(attribute) ⇒ Object



58
59
60
# File 'lib/generators/koi/helpers/attribute_helpers.rb', line 58

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

#index_attributesObject



70
71
72
# File 'lib/generators/koi/helpers/attribute_helpers.rb', line 70

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

#show_attribute_for(attribute) ⇒ Object



62
63
64
# File 'lib/generators/koi/helpers/attribute_helpers.rb', line 62

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

#show_attributesObject



74
75
76
# File 'lib/generators/koi/helpers/attribute_helpers.rb', line 74

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