Class: StripeLocal::Subscription

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
ObjectAdapter
Defined in:
app/models/stripe_local/subscription.rb

Class Method Summary collapse

Class Method Details

.create(object) ⇒ Object



14
15
16
# File 'app/models/stripe_local/subscription.rb', line 14

def create object
  super normalize( object )
end

.normalize(attrs) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/models/stripe_local/subscription.rb', line 18

def normalize attrs
  attrs.each_with_object({}) do |(k,v),h|
    key = case k.to_sym
    when :id       then next
    when :customer then :customer_id
    when :plan     then h[:plan_id] = v.id and next
    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