Sha256: b58d3c9ff5eb3daa551a3f31d28ff45f6b0e3889d36b5644531912ce16499a37

Contents?: true

Size: 1.03 KB

Versions: 1

Compression:

Stored size: 1.03 KB

Contents

module WepayRails
  module Helpers
    module ModelHelpers

      # Create a column on one of your models where the wepay authorization code
      # will be stored to be used for future transactions. Example:

      # add_column :users, :wepay_auth_code, :string

      # Then in your model, let's say the User model, you tell wepay-rails what the column name is:
      #
      # class User < ActiveRecord::Base
      #   wepayable :wepay_auth_code
      # end
      def wepayable(*args)
        @params = args.last if args.last.is_a?(Hash)
        @@wepayable_column ||= args.first.to_s

        File.open('/tmp/noisebytes.log','a') {|f| f.write("Args are #{args.inspect}\n")}
        File.open('/tmp/noisebytes.log','a') {|f| f.write("Column is #{@@wepayable_column}\n")}

        define_method "has_#{@@wepayable_column}?" do
          "self.#{@@wepayable_column}.present?"
        end

        define_method "save_#{@@wepayable_column}" do |value|
          "self.update_attribute(#{@@wepayable_column}, #{value})"
        end
      end

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
wepay-rails-0.1.52 lib/helpers/model_helpers.rb