Class: DevId::BasicActiveModel
- Inherits:
-
Object
- Object
- DevId::BasicActiveModel
- Extended by:
- ActiveModel::Naming
- Includes:
- ActiveModel::Conversion, ActiveModel::ForbiddenAttributesProtection, ActiveModel::MassAssignmentSecurity, ActiveModel::Validations
- Defined in:
- lib/dev-id/base.rb
Direct Known Subclasses
Instance Method Summary collapse
-
#assign_attributes(new_attributes, options = {}) ⇒ Object
see
activerecord/lib/active_record/attribute_assignment.rb. - #before_validation ⇒ Object
- #do_before_validation ⇒ Object
-
#initialize(attrs = {}) ⇒ BasicActiveModel
constructor
A new instance of BasicActiveModel.
- #persisted? ⇒ Boolean
Constructor Details
#initialize(attrs = {}) ⇒ BasicActiveModel
Returns a new instance of BasicActiveModel.
38 39 40 |
# File 'lib/dev-id/base.rb', line 38 def initialize( attrs={} ) assign_attributes( attrs ) end |
Instance Method Details
#assign_attributes(new_attributes, options = {}) ⇒ Object
see activerecord/lib/active_record/attribute_assignment.rb
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/dev-id/base.rb', line 43 def assign_attributes( new_attributes, ={} ) return unless new_attributes.present? attributes = new_attributes.stringify_keys unless [:without_protection] if ::ActiveModel::VERSION::MAJOR <= 3 attributes = sanitize_for_mass_assignment( attributes, [:as] || :default ) else attributes = sanitize_for_mass_assignment( attributes ) end end attributes.each { |k, v| #setter_name = :"#{k}=" #send( setter_name, v ) if respond_to?( setter_name ) send( :"#{k}=", v ) } #self nil end |
#before_validation ⇒ Object
75 76 77 |
# File 'lib/dev-id/base.rb', line 75 def before_validation # override in sub-classes end |
#do_before_validation ⇒ Object
70 71 72 73 |
# File 'lib/dev-id/base.rb', line 70 def do_before_validation @errors.clear before_validation() end |
#persisted? ⇒ Boolean
66 67 68 |
# File 'lib/dev-id/base.rb', line 66 def persisted? false end |