Sha256: c223accfb0f64ff3140fee8fa39a693d7de315cc0bda7824744280f9bab4c366

Contents?: true

Size: 1.04 KB

Versions: 6

Compression:

Stored size: 1.04 KB

Contents

module OmiseGO
  class Base
    class << self
      attr_accessor :attributes_list

      def attributes(*attrs)
        attr_accessor(*attrs)
        @attributes_list = attrs.map(&:to_sym)
      end

      def global_client
        Client.new
      end

      def request(client)
        (client || global_client).request
      end
    end

    attr_accessor :client, :original_payload

    def initialize(attributes, client: nil)
      self.class.attributes_list ||= []

      self.class.attributes_list.each do |name|
        instance_variable_set("@#{name}", attributes[name.to_sym] ||
                                          attributes[name.to_s])
      end

      self.original_payload = attributes
      @client = client || self.class.global_client
    end

    def inspect
      string = "#<#{self.class.name}:#{object_id} "
      fields = self.class.attributes_list.map do |field|
        "#{field}: #{send(field)}"
      end
      string << fields.join(', ') << '>'
    end

    def success?
      true
    end

    def error?
      false
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
omisego-0.12.0 lib/omisego/base.rb
omisego-0.11.0 lib/omisego/base.rb
omisego-0.10.0 lib/omisego/base.rb
omisego-0.9.6 lib/omisego/base.rb
omisego-0.9.5 lib/omisego/base.rb
omisego-0.9.4 lib/omisego/base.rb