Sha256: 2f621e0fe841bd473f56ea5a49960db82e4f6d9560419763607f0c9b1d11e848

Contents?: true

Size: 615 Bytes

Versions: 5

Compression:

Stored size: 615 Bytes

Contents

# frozen_string_literal: true
module Blacklight
  class Configuration::Field < OpenStructWithHashAccess
    def normalize! blacklight_config = nil
      self.field ||= self.key
      self.key ||= self.field

      self.label ||= default_label

      self.if = true if self.if.nil?
      self.unless = false if self.unless.nil?

      self
    end
  
    def validate!
      raise ArgumentError, "Must supply a field name" if self.field.nil?
    end

    def default_label
      if self.key.respond_to?(:titleize)
        self.key.try(:titleize)
      else
        self.key.to_s.titleize
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
blacklight-6.3.3 lib/blacklight/configuration/field.rb
blacklight-6.3.1 lib/blacklight/configuration/field.rb
blacklight-6.3.0 lib/blacklight/configuration/field.rb
blacklight-6.2.0 lib/blacklight/configuration/field.rb
blacklight-6.1.0 lib/blacklight/configuration/field.rb