Sha256: 0e28cdc58e5a0380b8fbb94e220e52e491c54616729eb015ebbfd61feac92295

Contents?: true

Size: 602 Bytes

Versions: 3

Compression:

Stored size: 602 Bytes

Contents

# frozen_string_literal: true

module Phlexi
  module Form
    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

3 entries across 3 versions & 1 rubygems

Version Path
phlexi-form-0.3.0 lib/phlexi/form/field_options/labels.rb
phlexi-form-0.3.0.rc1 lib/phlexi/form/field_options/labels.rb
phlexi-form-0.2.0 lib/phlexi/form/field_options/labels.rb