Sha256: 3b078f1c7646e7d0fc932a973ac10f958be3d49bffb255af137fd4d67f4dbb48

Contents?: true

Size: 1.11 KB

Versions: 6

Compression:

Stored size: 1.11 KB

Contents

module StripeLocal
  class Plan < ActiveRecord::Base
    include SyncPlans

    self.primary_key = :id

    has_many :subscriptions, inverse_of: :plan
    has_many :line_items, inverse_of: :plan
    has_many :members,  through: :subscriptions,
                        inverse_of: :plan,
                        source: :customer
    has_many :invoices, through: :line_items,
                        source: :invoice

    class<<self
      def create object
        if found = find_by( id: object[:id] )
          found.update_attributes synced: true
        else
          super normalize object
        end
      end

      def normalize attrs
        attrs.each_with_object({}) do |(k,v),h|
          key = case k.to_sym
          when :livemode then h[:synced] = true and next
          when ->(x){ attribute_method? x } then k.to_sym
          else next
          end
          h[key] = v
        end
      end
    end

  #=!=#>>>
  # string   :id
  # string   :name
  # integer  :amount
  # string   :interval
  # integer  :interval_count
  # integer  :trial_period_days
  # string   :currency
  # boolean  :synced
  #=ยก=#>>>
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

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