module ActiverecordCashier
Constants
- DELIMITER
- PREFIX
- VERSION
Public Class Methods
demorph(*tags)
click to toggle source
# File lib/activerecord_cashier.rb, line 31 def demorph(*tags) tags.flatten! tags.map do |tag| if tag.index(PREFIX) == 0 parts = tag[PREFIX.length..-1].split(DELIMITER) if parts.length == 1 parts.first.constantize else parts.length == 2 parts.first.constantize.find_by_id(parts.last.to_i) end else tag end end end
morph(*tags)
click to toggle source
# File lib/activerecord_cashier.rb, line 17 def morph(*tags) tags.flatten! tags.map do |tag| if tag.is_a? String tag elsif tag.is_a? Class PREFIX + tag.to_s elsif tag.is_a?(ActiveRecord::Base) "#{PREFIX}#{tag.class.to_s}#{DELIMITER}#{tag.try :id}" end end.flatten end