Class: CanCan::ControllerResource

Inherits:
Object
  • Object
show all
Defined in:
lib/cancan/controller_resource.rb

Overview

:nodoc:

Instance Method Summary collapse

Constructor Details

#initialize(controller, name, parent = nil, options = {}) ⇒ ControllerResource

Returns a new instance of ControllerResource.



3
4
5
6
7
8
# File 'lib/cancan/controller_resource.rb', line 3

def initialize(controller, name, parent = nil, options = {})
  @controller = controller
  @name = name
  @parent = parent
  @options = options
end

Instance Method Details

#build(attributes) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/cancan/controller_resource.rb', line 18

def build(attributes)
  if base.kind_of? Class
    self.model_instance ||= base.new(attributes)
  else
    self.model_instance ||= base.build(attributes)
  end
end

#find(id) ⇒ Object



14
15
16
# File 'lib/cancan/controller_resource.rb', line 14

def find(id)
  self.model_instance ||= base.find(id)
end

#model_classObject



10
11
12
# File 'lib/cancan/controller_resource.rb', line 10

def model_class
  @options[:class] || @name.to_s.camelize.constantize
end

#model_instanceObject



26
27
28
# File 'lib/cancan/controller_resource.rb', line 26

def model_instance
  @controller.instance_variable_get("@#{@name}")
end

#model_instance=(instance) ⇒ Object



30
31
32
# File 'lib/cancan/controller_resource.rb', line 30

def model_instance=(instance)
  @controller.instance_variable_set("@#{@name}", instance)
end