Class: TableHelp::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/table_help/config.rb

Constant Summary collapse

DEFAULT_OPTIONS =
{
  table_for: {
    class: "table table-striped table-hover table_for",
  },
  attributes_table_for: {
    class: "table table-striped table-hover attributes_table_for",
  },
}.freeze
DEFAULT_FORMATTER =
{
  attribute_name: ->(name, collection_or_resource) do
    case collection_or_resource
    when ActiveRecord::Relation
      collection_or_resource.model.human_attribute_name(name)
    when Enumerable
      collection_or_resource.first.class.human_attribute_name(name)
    else
      collection_or_resource.class.human_attribute_name(name)
    end
  end,
  value: ->(name, value) do
    case value
    when DateTime, Time
      I18n.l(value)
    when Numeric
      name.to_s.match?(/\Aid\z|_id\z/) ? value : value.to_s(:delimited)
    when TrueClass, FalseClass
      value.to_s
    else
      value
    end
  end,
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



39
40
41
42
# File 'lib/table_help/config.rb', line 39

def initialize
  @default_options = DEFAULT_OPTIONS
  @formatter = DEFAULT_FORMATTER
end

Instance Attribute Details

#default_optionsObject

Returns the value of attribute default_options.



37
38
39
# File 'lib/table_help/config.rb', line 37

def default_options
  @default_options
end

#formatterObject

Returns the value of attribute formatter.



37
38
39
# File 'lib/table_help/config.rb', line 37

def formatter
  @formatter
end