Module: Modesty::IdentityMethods

Included in:
API
Defined in:
lib/modesty/identity.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#identityObject (readonly)

Returns the value of attribute identity.



7
8
9
# File 'lib/modesty/identity.rb', line 7

def identity
  @identity
end

Instance Method Details

#identify!(id, opts = {}) ⇒ Object



9
10
11
12
13
14
15
16
17
18
# File 'lib/modesty/identity.rb', line 9

def identify!(id, opts={})
  unless opts[:ignore]
    raise(
      IdentityError,
      "Identity must be an integer or nil."
    ) unless id.nil? || id.is_a?(Fixnum)

    @identity = id
  end
end

#with_identity(id) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/modesty/identity.rb', line 20

def with_identity(id)
  old_identity = Modesty.identity
  Modesty.identify! id
  ret = yield
  Modesty.identify! old_identity
  ret
end