Sha256: 5f564c425d6477236f78454e23221d85c17547fb839c840fd3aab4d83898b9ef

Contents?: true

Size: 603 Bytes

Versions: 1

Compression:

Stored size: 603 Bytes

Contents

# frozen_string_literal: true

module Phlexi
  module Table
    module FieldOptions
      module Labels
        def label(label = nil)
          if label.nil?
            options[:label] = options.fetch(:label) { calculate_label }
          else
            options[:label] = label
            self
          end
        end

        private

        def calculate_label
          if object.class.respond_to?(:human_attribute_name)
            object.class.human_attribute_name(key.to_s, {base: object})
          else
            key.to_s.humanize
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
phlexi-table-0.0.1 lib/phlexi/table/field_options/labels.rb