Sha256: 06e3ddc17dee8075c32c1c30c9b8fed57b36b29f0abb9335a74aa7b673fd8824

Contents?: true

Size: 1.07 KB

Versions: 11

Compression:

Stored size: 1.07 KB

Contents

module StripeLocal
  module ObjectAdapter
    extend ActiveSupport::Concern

    module ClassMethods
      def find_remote id
        object = stripe_object.retrieve id
        new object
      end

      # read access to stripe object
      def stripe_object
        @stripe_object ||= Object.qualified_const_get "Stripe::#{self.to_s.classify}"
      end

      #=!=#
      # attr_accessor like <tt>macro</tt> for DateTime columns of a localized Stripe Object class
      # to use:
      #   * Pass in one or more symbolized column names.
      # Generates setter methods for converting JSON style `epoch` timestamps to the proper DateTime values your database expects.
      # +Note:+ Regular <tt>DateTime</tt> objects are perfectly acceptable as arguments because the value is always coerced into an <tt>Integer</tt> before conversion.
      #=ยก=#
      def time_writer *array_of_syms
        array_of_syms.each do |sym|
          define_method ":#{sym}=" do |epoch|
            write_attribute sym, Time.at( epoch.to_i ) unless epoch.nil?
          end
        end
      end
    end

  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
stripe_local-0.2.5 app/mixins/stripe_local/object_adapter.rb
stripe_local-0.2.4 app/mixins/stripe_local/object_adapter.rb
stripe_local-0.2.3 app/mixins/stripe_local/object_adapter.rb
stripe_local-0.2.2 app/mixins/stripe_local/object_adapter.rb
stripe_local-0.2.1 app/mixins/stripe_local/object_adapter.rb
stripe_local-0.2.0 app/mixins/stripe_local/object_adapter.rb
stripe_local-0.1.3 app/mixins/stripe_local/object_adapter.rb
stripe_local-0.1.2 app/mixins/stripe_local/object_adapter.rb
stripe_local-0.1.1 app/mixins/stripe_local/object_adapter.rb
stripe_local-0.1.0 app/mixins/stripe_local/object_adapter.rb
stripe_local-0.0.2 app/mixins/stripe_local/object_adapter.rb