Class: DudePolicy::Dude

Inherits:
Object
  • Object
show all
Defined in:
lib/dude_policy/dude.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(current_dude) ⇒ Dude

Returns a new instance of Dude.



5
6
7
# File 'lib/dude_policy/dude.rb', line 5

def initialize(current_dude)
  @dude = current_dude
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, resource) ⇒ Object



14
15
16
# File 'lib/dude_policy/dude.rb', line 14

def method_missing(name, resource)
  resource.policy.send(name, dude: dude)
end

Instance Attribute Details

#dudeObject (readonly)

Returns the value of attribute dude.



3
4
5
# File 'lib/dude_policy/dude.rb', line 3

def dude
  @dude
end

Instance Method Details

#inspectObject



9
10
11
12
# File 'lib/dude_policy/dude.rb', line 9

def inspect
  id = "##{dude.id}" if dude.respond_to?(:id)
  "<#DudePolicy::Dude##{object_id} #{dude.class.name}#{id}>"
end

#respond_to?Boolean

RSpec mocks are checking if object responds to calls Due to fact that we use method_missing is delegating responsibility Dude class responds to all calls

Returns:

  • (Boolean)


21
22
23
# File 'lib/dude_policy/dude.rb', line 21

def respond_to?(*)
  true
end