module Authentication::Attributes
Constants
- DEFAULT_ID_ATTRIBUTE
- DEFAULT_PRIVATE_ATTRIBUTE
- DEFAULT_PUBLIC_ATTRIBUTE
Public Instance Methods
alias_accessor(name, name_method = nil) { || ... }
click to toggle source
# File lib/authentication/attributes.rb, line 84 def alias_accessor(name, name_method = nil) method_name = send name_method || name if method_name.present? && method_name.to_s != name.to_s remove_method method_name if respond_to? method_name remove_method "#{method_name}=" if respond_to? "#{method_name}=" end yield method_name = send name_method || name if method_name.to_s != name.to_s alias_method method_name, name alias_method "#{method_name}=", "#{name}=" end end
authenticated_model_name()
click to toggle source
# File lib/authentication/attributes.rb, line 59 def authenticated_model_name authenticated_model.present? ? authenticated_model.to_s.underscore.gsub('/', '_').to_sym : :model end
columns()
click to toggle source
# File lib/authentication/attributes.rb, line 75 def columns [ Struct.new(:name, :type).new(public_attribute, :string), Struct.new(:name, :type).new(private_attribute, :string) ] end
has_id(attribute)
click to toggle source
# File lib/authentication/attributes.rb, line 41 def has_id(attribute) alias_accessor :id, :id_attribute do @id_attribute = attribute.to_s.to_sym.presence end end
has_model(name)
click to toggle source
# File lib/authentication/attributes.rb, line 35 def has_model(name) alias_accessor :model, :authenticated_model_name do @authenticated_model = name.present? ? name.to_s.classify.constantize : nil end end
has_private(attribute)
click to toggle source
# File lib/authentication/attributes.rb, line 53 def has_private(attribute) alias_accessor :private_attribute do @private_attribute = attribute.to_s.to_sym.presence end end
has_public(attribute)
click to toggle source
# File lib/authentication/attributes.rb, line 47 def has_public(attribute) alias_accessor :public_attribute do @public_attribute = attribute.to_s.to_sym.presence end end
id()
click to toggle source
# File lib/authentication/attributes.rb, line 12 def id return nil if model.blank? model.send self.class.id_attribute end
id=(v)
click to toggle source
# File lib/authentication/attributes.rb, line 17 def id=(v) return self.model = nil if v.nil? self.model = self.class.authenticated_model.find_by self.class.id_attribute => v end
id_attribute()
click to toggle source
# File lib/authentication/attributes.rb, line 63 def id_attribute @id_attribute || DEFAULT_ID_ATTRIBUTE end
model()
click to toggle source
# File lib/authentication/attributes.rb, line 22 def model return nil if public_attribute.blank? self.class.authenticated_model.find_by self.class.public_attribute => public_attribute end
model=(v)
click to toggle source
# File lib/authentication/attributes.rb, line 27 def model=(v) self.public_attribute = v.try self.class.public_attribute end
private_attribute()
click to toggle source
# File lib/authentication/attributes.rb, line 71 def private_attribute @private_attribute || DEFAULT_PRIVATE_ATTRIBUTE end
public_attribute()
click to toggle source
# File lib/authentication/attributes.rb, line 67 def public_attribute @public_attribute || DEFAULT_PUBLIC_ATTRIBUTE end