Class: Avo::PhotoObject

Inherits:
Object
  • Object
show all
Defined in:
lib/avo/photo_object.rb

Direct Known Subclasses

CoverPhoto, ProfilePhoto

Instance Method Summary collapse

Constructor Details

#initialize(resource:) ⇒ PhotoObject

Returns a new instance of PhotoObject.



4
5
6
# File 'lib/avo/photo_object.rb', line 4

def initialize(resource:)
  @resource = resource
end

Instance Method Details

#optionsObject



11
12
13
14
15
16
17
# File 'lib/avo/photo_object.rb', line 11

def options
  @options ||= if @resource.class&.send(key).present?
    @resource.class&.send(key)
  else
    {}
  end
end

#present?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/avo/photo_object.rb', line 37

def present?
  value.present?
end

#valueObject



19
20
21
22
23
24
25
26
27
# File 'lib/avo/photo_object.rb', line 19

def value
  return unless options.fetch(:source, nil).present?

  if options[:source].is_a?(Symbol)
    record.send(options[:source])
  elsif options[:source].respond_to?(:call)
    Avo::ExecutionContext.new(target: options[:source], record:, resource: @resource, view:).handle
  end
end

#visible_in_current_view?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/avo/photo_object.rb', line 33

def visible_in_current_view?
  send(:"visible_on_#{view}?")
end

#visible_onObject



29
30
31
# File 'lib/avo/photo_object.rb', line 29

def visible_on
  @visible_on ||= Array.wrap(options[:visible_on] || [:show, :forms])
end

#visible_on_edit?Boolean

Returns:

  • (Boolean)


45
# File 'lib/avo/photo_object.rb', line 45

def visible_on_edit? = visible_in_either?(:edit, :forms)

#visible_on_index?Boolean

Returns:

  • (Boolean)


41
# File 'lib/avo/photo_object.rb', line 41

def visible_on_index? = visible_in_either?(:index, :display)

#visible_on_new?Boolean

Returns:

  • (Boolean)


47
# File 'lib/avo/photo_object.rb', line 47

def visible_on_new? = visible_in_either?(:new, :forms)

#visible_on_show?Boolean

Returns:

  • (Boolean)


43
# File 'lib/avo/photo_object.rb', line 43

def visible_on_show? = visible_in_either?(:show, :display)