Class: Administrate::Field::Deferred

Inherits:
Object
  • Object
show all
Defined in:
lib/administrate/field/deferred.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(deferred_class, options = {}) ⇒ Deferred

Returns a new instance of Deferred.



6
7
8
9
# File 'lib/administrate/field/deferred.rb', line 6

def initialize(deferred_class, options = {})
  @deferred_class = deferred_class
  @options = options
end

Instance Attribute Details

#deferred_classObject (readonly)

Returns the value of attribute deferred_class.



11
12
13
# File 'lib/administrate/field/deferred.rb', line 11

def deferred_class
  @deferred_class
end

#optionsObject (readonly)

Returns the value of attribute options.



11
12
13
# File 'lib/administrate/field/deferred.rb', line 11

def options
  @options
end

Instance Method Details

#==(other) ⇒ Object



18
19
20
21
22
# File 'lib/administrate/field/deferred.rb', line 18

def ==(other)
  other.respond_to?(:deferred_class) &&
    deferred_class == other.deferred_class &&
    options == other.options
end

#associative?Boolean

Returns:



28
29
30
# File 'lib/administrate/field/deferred.rb', line 28

def associative?
  deferred_class.associative?
end

#eager_load?Boolean

Returns:



32
33
34
# File 'lib/administrate/field/deferred.rb', line 32

def eager_load?
  deferred_class.eager_load?
end

#getterObject



24
25
26
# File 'lib/administrate/field/deferred.rb', line 24

def getter
  options.fetch(:getter, nil)
end

#new(*args) ⇒ Object



13
14
15
16
# File 'lib/administrate/field/deferred.rb', line 13

def new(*args)
  new_options = args.last.respond_to?(:merge) ? args.pop : {}
  deferred_class.new(*args, options.merge(new_options))
end

#permitted_attribute(attr, opts = {}) ⇒ Object



59
60
61
62
63
64
65
66
# File 'lib/administrate/field/deferred.rb', line 59

def permitted_attribute(attr, opts = {})
  if options.key?(:foreign_key)
    Administrate.warn_of_deprecated_option(:foreign_key)
    options.fetch(:foreign_key)
  else
    deferred_class.permitted_attribute(attr, options.merge(opts))
  end
end

#searchable?Boolean

Returns:



36
37
38
39
40
41
42
# File 'lib/administrate/field/deferred.rb', line 36

def searchable?
  if options.key?(:getter)
    false
  else
    options.fetch(:searchable, deferred_class.searchable?)
  end
end

#searchable_fieldObject



44
45
46
47
48
49
# File 'lib/administrate/field/deferred.rb', line 44

def searchable_field
  Administrate.deprecator.warn(
    "searchable_field is deprecated, use searchable_fields instead"
  )
  options.fetch(:searchable_field)
end

#searchable_fieldsObject



51
52
53
54
55
56
57
# File 'lib/administrate/field/deferred.rb', line 51

def searchable_fields
  if options.key?(:searchable_field)
    [searchable_field]
  else
    options.fetch(:searchable_fields)
  end
end