class Administrate::Field::Base

Attributes

attribute[R]
data[R]
options[R]
page[R]
resource[R]

Public Class Methods

associative?() click to toggle source
# File lib/administrate/field/base.rb, line 15
def self.associative?
  self < Associative
end
eager_load?() click to toggle source
# File lib/administrate/field/base.rb, line 19
def self.eager_load?
  false
end
field_type() click to toggle source
# File lib/administrate/field/base.rb, line 27
def self.field_type
  to_s.split("::").last.underscore
end
html_class() click to toggle source
# File lib/administrate/field/base.rb, line 11
def self.html_class
  field_type.dasherize
end
new(attribute, data, page, options = {}) click to toggle source
# File lib/administrate/field/base.rb, line 35
def initialize(attribute, data, page, options = {})
  @attribute = attribute
  @data = data
  @page = page
  @resource = options.delete(:resource)
  @options = options
end
permitted_attribute(attr, _options = nil) click to toggle source
# File lib/administrate/field/base.rb, line 31
def self.permitted_attribute(attr, _options = nil)
  attr
end
searchable?() click to toggle source
# File lib/administrate/field/base.rb, line 23
def self.searchable?
  false
end
with_options(options = {}) click to toggle source
# File lib/administrate/field/base.rb, line 7
def self.with_options(options = {})
  Deferred.new(self, options)
end

Public Instance Methods

html_class() click to toggle source
# File lib/administrate/field/base.rb, line 43
def html_class
  self.class.html_class
end
name() click to toggle source
# File lib/administrate/field/base.rb, line 47
def name
  attribute.to_s
end
required?() click to toggle source
# File lib/administrate/field/base.rb, line 55
def required?
  return false unless resource.class.respond_to?(:validators_on)

  resource.class.validators_on(attribute).any? do |v|
    next false unless v.class == ActiveRecord::Validations::PresenceValidator

    options = v.options
    next false if options.include?(:if)
    next false if options.include?(:unless)

    if on_option = options[:on]
      if on_option == :create && !resource.persisted?
        next true
      end

      if on_option == :update && resource.persisted?
        next true
      end

      next false
    end

    true
  end
end
to_partial_path() click to toggle source
# File lib/administrate/field/base.rb, line 51
def to_partial_path
  "/fields/#{self.class.field_type}/#{page}"
end