Sha256: 95791dca2ddc976ae05c1c956425711238f2456a9b229341a7b299cc2684b5ae

Contents?: true

Size: 1.1 KB

Versions: 6

Compression:

Stored size: 1.1 KB

Contents

module StripeLocal
  class Transaction < ActiveRecord::Base
    include ObjectAdapter

    self.primary_key = :id

    time_writer :created, :available_on


    belongs_to :source, polymorphic: true

    class<<self
      def create object
        super normalize( object )
      end

      def normalize attrs
        attrs.each_with_object({}) do |(k,v),h|
          key = case k.to_sym
          when :source then :source_id
          when :type   then :source_type
          when ->(x){attribute_method? x} then k.to_sym
          else next
          end
          if v.is_a?(Numeric) && v > 1000000000
            h[key] = Time.at( v )
          else
            h[key] = v
          end
        end
      end

      def pending
        where 'available_on < ?', Time.now
      end

      def available
        where 'available_on > ?', Time.now
      end
    end


  #=!=#>>>
  # string   :id
  # integer  :amount
  # datetime :available_on
  # datetime :created
  # integer  :fee
  # integer  :net
  # string   :source_id
  # string   :source_type
  # string   :status
  # string   :description
  #=ยก=#>>>
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
stripe_local-0.2.5 app/models/stripe_local/transaction.rb
stripe_local-0.2.4 app/models/stripe_local/transaction.rb
stripe_local-0.2.3 app/models/stripe_local/transaction.rb
stripe_local-0.2.2 app/models/stripe_local/transaction.rb
stripe_local-0.2.1 app/models/stripe_local/transaction.rb
stripe_local-0.2.0 app/models/stripe_local/transaction.rb