Module: Traits::Utilities
- Included in:
- Traits
- Defined in:
- lib/traits/utilities.rb
Instance Method Summary collapse
- #active_record_descendant?(obj) ⇒ Boolean
- #active_record_instance?(obj) ⇒ Boolean
- #retrieve_model_class(obj) ⇒ Object
- #valid_active_record_identifier?(id) ⇒ Boolean
Instance Method Details
#active_record_descendant?(obj) ⇒ Boolean
26 27 28 |
# File 'lib/traits/utilities.rb', line 26 def active_record_descendant?(obj) obj.kind_of?(Class) && obj < ActiveRecord::Base end |
#active_record_instance?(obj) ⇒ Boolean
30 31 32 |
# File 'lib/traits/utilities.rb', line 30 def active_record_instance?(obj) obj.kind_of?(ActiveRecord::Base) end |
#retrieve_model_class(obj) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/traits/utilities.rb', line 9 def retrieve_model_class(obj) if active_record_descendant?(obj) obj elsif active_record_instance?(obj) obj.class else case obj when Symbol then obj.to_s.camelize.constantize when String then obj.camelize.constantize when Model then obj.model_class else raise UnidentifiedModelReference, obj end end end |
#valid_active_record_identifier?(id) ⇒ Boolean
34 35 36 |
# File 'lib/traits/utilities.rb', line 34 def valid_active_record_identifier?(id) id.kind_of?(String) || id.kind_of?(Numeric) end |