Class: DevId::BasicActiveModel

Inherits:
Object
  • Object
show all
Extended by:
ActiveModel::Naming
Includes:
ActiveModel::Conversion, ActiveModel::ForbiddenAttributesProtection, ActiveModel::MassAssignmentSecurity, ActiveModel::Validations
Defined in:
lib/dev-id/base.rb

Direct Known Subclasses

Base

Instance Method Summary collapse

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, options={} )
	return unless new_attributes.present?
	
	attributes = new_attributes.stringify_keys
	
	unless options[:without_protection]
		if ::ActiveModel::VERSION::MAJOR <= 3
			attributes = sanitize_for_mass_assignment( attributes, options[: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_validationObject



75
76
77
# File 'lib/dev-id/base.rb', line 75

def before_validation
	# override in sub-classes
end

#do_before_validationObject



70
71
72
73
# File 'lib/dev-id/base.rb', line 70

def do_before_validation
	@errors.clear
	before_validation()
end

#persisted?Boolean

Returns:

  • (Boolean)


66
67
68
# File 'lib/dev-id/base.rb', line 66

def persisted?
	false
end