Class: Gearhead::ResourceFinder

Inherits:
Object
  • Object
show all
Defined in:
lib/gearhead/resource_finder.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(gear, params) ⇒ ResourceFinder

Returns a new instance of ResourceFinder.



7
8
9
10
# File 'lib/gearhead/resource_finder.rb', line 7

def initialize(gear, params)
  @gear = gear
  @params = params
end

Class Method Details

.for(gear, params) ⇒ Object



3
4
5
# File 'lib/gearhead/resource_finder.rb', line 3

def self.for(gear, params)
  new(gear, params).resource
end

Instance Method Details

#resourceObject



12
13
14
15
16
17
18
# File 'lib/gearhead/resource_finder.rb', line 12

def resource
  if @gear._gear_finder.present?
    @gear._gear_finder.call(@params)
  else
    @gear.resource.find_by(@gear._gear_param_key => @params[:resource_id])
  end
end