Class: Commands::SearchResult

Inherits:
Object
  • Object
show all
Defined in:
app/models/kommandant/commands/search_result.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(command:, resource:) ⇒ SearchResult

Returns a new instance of SearchResult.



3
4
5
6
# File 'app/models/kommandant/commands/search_result.rb', line 3

def initialize(command:, resource:)
  @command = command
  @resource = resource
end

Instance Attribute Details

#resourceObject (readonly)

Returns the value of attribute resource.



8
9
10
# File 'app/models/kommandant/commands/search_result.rb', line 8

def resource
  @resource
end

Instance Method Details

#http_methodObject



25
26
27
# File 'app/models/kommandant/commands/search_result.rb', line 25

def http_method
  :get
end

#nameObject



11
12
13
14
15
16
17
# File 'app/models/kommandant/commands/search_result.rb', line 11

def name
  if command.translator.exists?(I18n.locale, "result_text")
    command.translator.translate(I18n.locale, "result_text")
  else
    indexed_attribute_for(resource, command.search_result_text_method)
  end
end

#pathObject



19
20
21
22
23
# File 'app/models/kommandant/commands/search_result.rb', line 19

def path
  return command.redirect_path.gsub(":id", resource.id.to_s) if command.redirect_path

  "/#{command.resource_class.downcase.pluralize}/#{resource.id}"
end