Class: NOMS::CMDB::Mock

Inherits:
HttpClient::RestMock show all
Defined in:
lib/noms/cmdb.rb

Constant Summary collapse

@@machine_id =
0

Instance Method Summary collapse

Methods inherited from HttpClient::RestMock

#all_data, #allow_partial_updates, #config_key, #default_content_type, #do_request, #ignore_content_type, #initialize, #maybe_read, #maybe_save

Methods inherited from HttpClient

#allow_partial_updates, #config_key, #dbg, #default_content_type, #ignore_content_type, #initialize, #ltrim, #method_missing, mock!, mockery, #myconfig, #opt, #rtrim, #trim

Constructor Details

This class inherits a constructor from NOMS::HttpClient::RestMock

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class NOMS::HttpClient

Instance Method Details

#allow_put_to_createObject



136
137
138
# File 'lib/noms/cmdb.rb', line 136

def allow_put_to_create
    false
end

#handle_mock(method, uri, opt) ⇒ Object



149
150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/noms/cmdb.rb', line 149

def handle_mock(method, uri, opt)
    if m = Regexp.new('/pcmsystemname/([^/]+)').match(uri.path)
        serial = m[1]
        @@machine_id += 1
        name = "m-%03d.mock" % @@machine_id
        do_request :POST => "system",
                   :body => {
                       'serial' => serial,
                       'fqdn' => name
                   }
    else
        false
    end
end

#id_field(path) ⇒ Object



140
141
142
143
144
145
146
147
# File 'lib/noms/cmdb.rb', line 140

def id_field(path)
    case path
    when %r{system$}
        'fqdn'
    else
        'id'
    end
end