Module: Coroutine::ActsAsLabel::Base::InstanceMethods

Defined in:
lib/acts_as_label/base.rb

Instance Method Summary collapse

Instance Method Details

#==(other) ⇒ Object

This method compares two values by running to_sym on both sides. This allows comparisons like the following:

u.role == Role.superuser
u.role == :superuser


215
216
217
# File 'lib/acts_as_label/base.rb', line 215

def ==(other)
  self.to_sym == (other.to_sym rescue false)
end

#to_aryObject

This method overrides to_ary to return nil, which tells anything trying to flatten this we are already flat. This is necessary because we are overriding active records method missing, which must do this somewhere in the bowels of rails.



189
190
191
# File 'lib/acts_as_label/base.rb', line 189

def to_ary
  nil
end

#to_sObject

This method overrides the to_s method to return the friendly label value.



196
197
198
# File 'lib/acts_as_label/base.rb', line 196

def to_s
  self.send("#{acts_as_label_label_column}")
end

#to_symObject

This method overrides the to_sym method to return the downcased symbolized system label value. This method is particularly useful in conjunction with role-based authorization systems.



205
206
207
# File 'lib/acts_as_label/base.rb', line 205

def to_sym
  self.send("#{acts_as_label_system_label_column}").underscore.to_sym
end