Sha256: bc1a8f98df8183c17dadf6ae23fa2de6830a3b466549e32525d7de28f40dd407
Contents?: true
Size: 1.55 KB
Versions: 16
Compression:
Stored size: 1.55 KB
Contents
class Kaui::TagDefinition < Kaui::Base define_attr :id define_attr :name define_attr :description define_attr :is_control_tag define_attr :applicable_object_types def self.all Kaui::KillbillHelper.get_tag_definitions end def self.find(tag_definition_id) Kaui::KillbillHelper.get_tag_definition(tag_definition_id) end # See com.ning.billing.util.dao.ObjectType in killbill-api %w(ACCOUNT ACCOUNT_EMAIL BUNDLE INVOICE PAYMENT INVOICE_ITEM INVOICE_PAYMENT SUBSCRIPTION SUBSCRIPTION_EVENT PAYMENT_METHOD REFUND TAG_DEFINITION).each do |object_type| define_singleton_method "all_for_#{object_type.downcase}" do self.all.delete_if { |tag_definition| !tag_definition.applicable_object_types.include? object_type } end end def save Kaui::KillbillHelper.create_tag_definition(self) # TODO - we should return the newly created id and update the model # @persisted = true end def destroy Kaui::KillbillHelper.delete_tag_definition(@id) @persisted = false end def is_system_tag? return false unless id.present? last_group = id.split('-')[4] is_system_tag = true last_group.split(//).each_with_index do |c, i| unless (c == '0' and i < 11) or (c.to_i > 0 and i == 11) is_system_tag = false break end end is_system_tag end def <=>(tag_definition) # System tags last return 1 if is_system_tag? and !tag_definition.is_system_tag? return -1 if !is_system_tag? and tag_definition.is_system_tag? @name <=> tag_definition.name end end
Version data entries
16 entries across 16 versions & 1 rubygems