Sha256: f31ba914481bef5e599c083d6ba8040ac0158d4542ed6bd75dc33867150881c1

Contents?: true

Size: 812 Bytes

Versions: 11

Compression:

Stored size: 812 Bytes

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)
        @column = args.first.to_s

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

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


    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
wepay-rails-0.1.34 lib/helpers/model_helpers.rb
wepay-rails-0.1.33 lib/helpers/model_helpers.rb
wepay-rails-0.1.32 lib/helpers/model_helpers.rb
wepay-rails-0.1.31 lib/helpers/model_helpers.rb
wepay-rails-0.1.30 lib/helpers/model_helpers.rb
wepay-rails-0.1.29 lib/helpers/model_helpers.rb
wepay-rails-0.1.28 lib/helpers/model_helpers.rb
wepay-rails-0.1.27 lib/helpers/model_helpers.rb
wepay-rails-0.1.26 lib/helpers/model_helpers.rb
wepay-rails-0.1.25 lib/helpers/model_helpers.rb
wepay-rails-0.1.24 lib/helpers/model_helpers.rb