@@ -27,8 +27,8 @@ module SoftLayer
2727 # for objects in that hierarchy
2828 #
2929 # The SoftLayer API represents entities as a hash of properties. This class
30- # stores that hash and uses +method_missing+ to allow code to access fields in
31- # that hash through simple method calls .
30+ # stores that hash and allows the use of subscripting to access those properties
31+ # directly .
3232 #
3333 # The class also has a model for making network requests that will refresh
3434 # the stored hash so that it reflects the most up-to-date information about
@@ -37,8 +37,15 @@ module SoftLayer
3737 # refresh_details to ask an object to update itself.
3838 #
3939 class ModelBase
40+ # The client environment that this model object belongs to
4041 attr_reader :softlayer_client
4142
43+ ##
44+ # :attr_reader: id
45+ # The unique identifier of this object within its API service
46+
47+ # Construct a new model object in the environment of the given client and
48+ # with the given hash of network data (presumably returned by the SoftLayer API)
4249 def initialize ( softlayer_client , network_hash )
4350 raise ArgumentError , "A hash is required" if nil == network_hash
4451
@@ -49,8 +56,18 @@ def initialize(softlayer_client, network_hash)
4956 raise ArgumentError , "id must be non-nil and non-empty" unless self [ :id ]
5057 end
5158
52- def to_ary
53- return nil
59+ ##
60+ # The service method of a Model object should return a SoftLayer Service
61+ # that best represents the modeled object. For example, a Ticket models
62+ # a particular entity in the SoftLayer_Ticket service. The particular
63+ # entity is identified by its id so the Ticket class would return
64+ #
65+ # softlayer_client["Ticket"].object_with_id
66+ #
67+ # which is a service which would allow calls to the ticket service
68+ # through that particular object.
69+ def service
70+ raise "Abstract method service in ModelBase was called"
5471 end
5572
5673 ##
@@ -72,7 +89,7 @@ def refresh_details(object_mask = nil)
7289 # of this routine.
7390 #
7491 def softlayer_properties ( object_mask = nil )
75- raise RuntimeError . new ( "Abstract method softlayer_properties in ModelBase was called" )
92+ raise "Abstract method softlayer_properties in ModelBase was called"
7693 end
7794
7895 ##
@@ -101,12 +118,17 @@ def self.sl_attr(attribute_symbol, hash_key = nil)
101118
102119 define_method ( attribute_symbol . to_sym ) { self [ hash_key ? hash_key : attribute_symbol . to_s ] }
103120 end
121+
122+ sl_attr :id
104123
105- ##
106- # :attr_reader: id
107- # The unique identifier of this object within it's API service
108- sl_attr ( :id )
109-
124+ # When printing to the console using puts, ruby will call the
125+ # to_ary method trying to convert an object into an array of lines
126+ # for stdio. We override to_ary to return nil for model objects
127+ # so they may be printed
128+ def to_ary ( )
129+ return nil ;
130+ end
131+
110132 protected
111133
112134 ##
0 commit comments