Class: ActiveSession::Base
- Inherits:
-
Object
- Object
- ActiveSession::Base
- Extended by:
- ActiveModel::Naming
- Includes:
- ActiveModel::AttributeMethods, ActiveModel::Conversion, ActiveModel::MassAssignmentSecurity, ActiveModel::Validations
- Defined in:
- lib/active_session/base.rb
Instance Method Summary collapse
- #assign_attributes(new_attributes, options = {}) ⇒ Object
- #attributes ⇒ Object
- #attributes=(attributes) ⇒ Object
-
#initialize(store, attributes = nil, options = {}) {|_self| ... } ⇒ Base
constructor
A new instance of Base.
- #persisted? ⇒ Boolean
Constructor Details
#initialize(store, attributes = nil, options = {}) {|_self| ... } ⇒ Base
Returns a new instance of Base.
11 12 13 14 15 16 |
# File 'lib/active_session/base.rb', line 11 def initialize(store, attributes = nil, = {}) @store = store @attributes = {} assign_attributes(attributes, ) 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, = {}) return unless new_attributes attributes = new_attributes.stringify_keys unless [:without_protection] attributes = sanitize_for_mass_assignment(attributes, .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 |
#attributes ⇒ Object
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
44 45 46 |
# File 'lib/active_session/base.rb', line 44 def persisted? false end |