Sha256: 10fe8939a17481d9eb3dc4f94146e83dd38b1271409baf01daa6dcf45f8ef1af

Contents?: true

Size: 811 Bytes

Versions: 13

Compression:

Stored size: 811 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

13 entries across 13 versions & 1 rubygems

Version Path
wepay-rails-0.1.48 lib/helpers/model_helpers.rb
wepay-rails-0.1.47 lib/helpers/model_helpers.rb
wepay-rails-0.1.46 lib/helpers/model_helpers.rb
wepay-rails-0.1.45 lib/helpers/model_helpers.rb
wepay-rails-0.1.44 lib/helpers/model_helpers.rb
wepay-rails-0.1.43 lib/helpers/model_helpers.rb
wepay-rails-0.1.42 lib/helpers/model_helpers.rb
wepay-rails-0.1.41 lib/helpers/model_helpers.rb
wepay-rails-0.1.40 lib/helpers/model_helpers.rb
wepay-rails-0.1.39 lib/helpers/model_helpers.rb
wepay-rails-0.1.38 lib/helpers/model_helpers.rb
wepay-rails-0.1.37 lib/helpers/model_helpers.rb
wepay-rails-0.1.36 lib/helpers/model_helpers.rb