Sha256: 82c9e864e907fbc7a2965acc044ae16be01f60a07e18c285a79c27d8330b3c0b

Contents?: true

Size: 1.19 KB

Versions: 8

Compression:

Stored size: 1.19 KB

Contents

module Braintree
  module BaseModule
    module Methods
      def return_object_or_raise(object_to_return)
        result = yield
        if result.success?
          result.send object_to_return
        else
          raise ValidationsFailed.new(result)
        end
      end

      def copy_instance_variables_from_object(object)
        object.instance_variables.each do |ivar|
          instance_variable_set ivar, object.instance_variable_get(ivar)
        end
      end

      def set_instance_variables_from_hash(hash)
        hash.each do |key, value|
          if key == :global_id
            instance_variable_set "@graphql_id", value
          elsif key == :android_pay_cards
            instance_variable_set "@google_pay_cards", value
          elsif key == :android_pay_card
            instance_variable_set "@google_pay_card", value
          elsif key == :android_pay_details
            instance_variable_set "@google_pay_details", value
          end

          instance_variable_set "@#{key}", value
        end
      end

      def singleton_class
        class << self; self; end
      end
    end

    def self.included(klass)
      klass.extend Methods
    end
    include Methods
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
braintree-4.23.0 lib/braintree/base_module.rb
braintree-4.22.0 lib/braintree/base_module.rb
braintree-4.21.0 lib/braintree/base_module.rb
braintree-4.20.0 lib/braintree/base_module.rb
braintree-4.19.0 lib/braintree/base_module.rb
braintree-4.18.0 lib/braintree/base_module.rb
braintree-4.17.0 lib/braintree/base_module.rb
braintree-4.16.0 lib/braintree/base_module.rb