Class: AdminIt::SingleContext

Inherits:
Context show all
Defined in:
lib/admin_it/context/single_context.rb

Direct Known Subclasses

SavableSingleContext, ShowContext

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

This class inherits a constructor from AdminIt::Context

Instance Attribute Details

#entityObject

Returns the value of attribute entity.



81
82
83
# File 'lib/admin_it/context/single_context.rb', line 81

def entity
  @entity
end

Class Method Details

.path(entity) ⇒ Object



73
74
75
76
77
78
# File 'lib/admin_it/context/single_context.rb', line 73

def self.path(entity)
  AdminIt::Engine.routes.url_helpers.send(
    "#{resource.name}_path",
    entity
  )
end

.sectionsObject



65
66
67
# File 'lib/admin_it/context/single_context.rb', line 65

def self.sections
  (@sections ||= {}).values
end

.single?Boolean

Returns:

  • (Boolean)


69
70
71
# File 'lib/admin_it/context/single_context.rb', line 69

def self.single?
  true
end

Instance Method Details

#path(_entity: nil) ⇒ Object



96
97
98
99
# File 'lib/admin_it/context/single_context.rb', line 96

def path(_entity: nil)
  _entity ||= entity
  self.class.path(_entity)
end

#sectionObject



101
102
103
# File 'lib/admin_it/context/single_context.rb', line 101

def section
  @section ||= sections.empty? ? :none : :general
end

#section=(value) ⇒ Object



105
106
107
108
109
110
111
112
113
114
# File 'lib/admin_it/context/single_context.rb', line 105

def section=(value)
  value = value.downcase.to_sym if value.is_a?(String)
  return unless value.is_a?(Symbol)
  if sections.empty?
    return if section != :none
  else
    return unless sections.map(&:name).include?(value)
  end
  @section = section
end

#valuesObject



91
92
93
94
# File 'lib/admin_it/context/single_context.rb', line 91

def values
  return {} if @entity.nil?
  Hash[fields(scope: :readable).map { |f| [f.name, f.read(@entity)] }]
end