Class: ActiveSession::Base

Inherits:
Object
  • Object
show all
Extended by:
ActiveModel::Naming
Includes:
ActiveModel::AttributeMethods, ActiveModel::Conversion, ActiveModel::MassAssignmentSecurity, ActiveModel::Validations
Defined in:
lib/active_session/base.rb

Instance Method Summary collapse

Constructor Details

#initialize(store, attributes = nil, options = {}) {|_self| ... } ⇒ Base

Returns a new instance of Base.

Yields:

  • (_self)

Yield Parameters:



11
12
13
14
15
16
# File 'lib/active_session/base.rb', line 11

def initialize(store, attributes = nil, options = {})
  @store = store
  @attributes = {}
  assign_attributes(attributes, options) if attributes
  yield self if block_given?
end

Instance Method Details

#assign_attributes(new_attributes, options = {}) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/active_session/base.rb', line 26

def assign_attributes(new_attributes, options = {})
  return unless new_attributes

  attributes = new_attributes.stringify_keys

  unless options[:without_protection]
    attributes = sanitize_for_mass_assignment(attributes, options.fetch(:as, :default))
  end

  attributes.each do |key, value|
    if respond_to?("#{key}=")
      send("#{key}=", value)
    else
      raise ActiveSession::UnknownAttributeError, "unknown attribute: #{key}"
    end
  end
end

#attributesObject



18
19
20
# File 'lib/active_session/base.rb', line 18

def attributes
  @attributes
end

#attributes=(attributes) ⇒ Object



22
23
24
# File 'lib/active_session/base.rb', line 22

def attributes=(attributes)
  assign_attributes(attributes)
end

#persisted?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/active_session/base.rb', line 44

def persisted?
  false
end