class AttrPassword::Adapters::ActiveRecord

The ActiveRecord adapter

Public Class Methods

inject!() click to toggle source

Attempt to inject the AttrPassword class into ActiveRecord::Base

Example:

>> AttrPassword::Adapters::ActiveRecord.inject!
=> nil
# File lib/attr_password/adapters/active_record.rb, line 13
def inject!
  # Ensure the ActiveRecord::Base class is defined
  return false unless defined?(::ActiveRecord::Base)

  # Make the ActiveRecord::Base class extend the AttrPassword class
  ::ActiveRecord::Base.send(:extend, AttrPassword)

  true
end

Public Instance Methods

available?() click to toggle source

Check if this adapter can be used for the object

Example:

>> adapter.available?
=> true
# File lib/attr_password/adapters/active_record.rb, line 30
def available?
  # Ensure the ActiveRecord::Base class is defined
  return false unless defined?(::ActiveRecord::Base)

  # Check if the object inherits from ActiveRecord::Base
  @object.class.ancestors.include?(::ActiveRecord::Base)
end
read_attribute(attribute) click to toggle source

Read an attribute

Example:

>> adapter.read_attribute(:hello_world)
=> "Hello, World!"
# File lib/attr_password/adapters/active_record.rb, line 44
def read_attribute(attribute)
  @object.send(:read_attribute, attribute.to_sym)
end
write_attribute(attribute, value) click to toggle source

Write an attribute

Example:

>> adapter.write_attribute(:hello_world, "Hello, World!")
=> true
# File lib/attr_password/adapters/active_record.rb, line 54
def write_attribute(attribute, value)
  @object.send(:write_attribute, attribute, value)
end