Sha256: 40c3c63a04426abdc62c313717a69e285f9dd18c702414a8f681aa2cf1f341af
Contents?: true
Size: 1.41 KB
Versions: 3
Compression:
Stored size: 1.41 KB
Contents
module StripeLocal class LineItem < ActiveRecord::Base include ObjectAdapter self.primary_key = :id belongs_to :invoice, inverse_of: :lines belongs_to :plan, inverse_of: :line_items time_writer :period_start, :period_end def metadata MultiJson.load read_attribute( :metadata ), symbolize_keys: true end class<<self def create attr_hash super normalize( attr_hash ) end def normalize attrs attrs.each_with_object({}) do |(k,v),h| key = case k.to_sym when :invoice then :invoice_id when :plan then h[:plan_id] = ( v.nil? ? "" : v.id ) and next # will be nil if this is a one off charge when :metadata then h[:metadata] = MultiJson.dump( v.try :to_hash ) and next when :type then h[:subscription] = (v == "subscription" ? true : false) and next when :period then h[:period_start] = Time.at(v.start) and h[:period_end] = Time.at(v.end) and next when ->(x){attribute_method? x} then k.to_sym else next end h[key] = v end end end end #=!=# # ==Database Schema # # string :id # string :invoice_id # boolean :subscription # integer :amount # string :currency # boolean :proration # datetime :period_start # datetime :period_end # integer :quantity # string :plan_id # string :description # text :metadata #=ยก=# end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
stripe_local-0.2.5 | app/models/stripe_local/line_item.rb |
stripe_local-0.2.4 | app/models/stripe_local/line_item.rb |
stripe_local-0.2.3 | app/models/stripe_local/line_item.rb |