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
    if collection_or_resource.respond_to?(:model)
      collection_or_resource.model.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_sym == :id) ? value : value.to_s(:delimited)
    else
      value
    end
  end,
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



34
35
36
37
# File 'lib/table_help/config.rb', line 34

def initialize
  @default_options = DEFAULT_OPTIONS
  @formatter = DEFAULT_FORMATTER
end

Instance Attribute Details

#default_optionsObject

Returns the value of attribute default_options.



32
33
34
# File 'lib/table_help/config.rb', line 32

def default_options
  @default_options
end

#formatterObject

Returns the value of attribute formatter.



32
33
34
# File 'lib/table_help/config.rb', line 32

def formatter
  @formatter
end