Sha256: d8a9ee43022ecbe7e24becdede13f7d5e55250e5186edaf6af77e813e222600b

Contents?: true

Size: 1.15 KB

Versions: 1

Compression:

Stored size: 1.15 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)
        wepayable_log = File.open('/tmp/wepayable.log','a')

        wepayable_log.puts "Wepayable column is #{wepayable_column}"

        # @wepayable_column is initilized in the Rails::Engine now
        # and pulled from the wepay.yml file
        define_method "has_#{wepayable_column}?" do
          self.send(wepayable_column.to_sym).present?
        end

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

      def wepayable_column
        WepayRails::Engine.wepayable_column
      end

      def wepayable_class
        WepayRails::Engine.wepayable_class
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

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