Class: FatZebra::Models::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/fat_zebra/models/base.rb

Direct Known Subclasses

Card, Purchase, Refund

Constant Summary collapse

@@attributes =
[]

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attrs = {}) ⇒ Base

Returns a new instance of Base.



13
14
15
16
17
18
19
# File 'lib/fat_zebra/models/base.rb', line 13

def initialize(attrs = {})
  attrs.each do |key, val|
    self.send("#{key}=", val) if self.respond_to?("#{key}=")
  end

  self.raw = attrs if self.respond_to?(:raw=)
end

Class Method Details

.attribute(*values) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/fat_zebra/models/base.rb', line 5

def self.attribute(*values)
  @@attributes ||= []
  values.each do |val|
    @@attributes << val
  end
  attr_accessor *values
end

Instance Method Details

#inspectObject



21
22
23
24
25
26
# File 'lib/fat_zebra/models/base.rb', line 21

def inspect
  inspection = @@attributes.collect { |name|
                  "#{name}: #{instance_variable_get("@#{name}")}"
                }.compact.join(", ")
  "#<#{self.class} #{inspection}>"
end

#to_sObject



28
29
30
# File 'lib/fat_zebra/models/base.rb', line 28

def to_s
  inspect
end