Skip to content

Commit

Permalink
Move code and ensure proper requires
Browse files Browse the repository at this point in the history
General things concerning AeolusClient namespace are moved to
aeolus_client.rb.

Logging configuration that is done by requiring aeolus_client/base.rb is
marked as FIXME for removal when configuration refactoring is done.

Require aeolus_client/base.rb for resource classes that inherit from it.
  • Loading branch information
jistr committed Feb 1, 2013
1 parent 8814b40 commit c501f73
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 28 deletions.
24 changes: 24 additions & 0 deletions lib/aeolus_client.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
require 'active_resource'

module AeolusClient
end

module ActiveResource
class Errors < ActiveModel::Errors
# Grabs errors from an XML response.
def from_xml(xml, save_cache = false)
array = Array.wrap(Hash.from_xml(xml)['errors']['error'])
# The below is added because the default behaviour (the above
# line) only works fine if the error string is not buried in
# another layer of xml.
#
# from_array (in this Errors class) is brittle and will blow up
# if it doesn't get an array of strings.
if array.size >= 1 && array[0].is_a?(Hash) &&
array[0].has_key?('message')
array.map! {|error| error['message']}
end
from_array array, save_cache
end
end
end
30 changes: 2 additions & 28 deletions lib/aeolus_client/base.rb
Original file line number Diff line number Diff line change
@@ -1,36 +1,10 @@
require 'active_resource'
require 'aeolus_cli'
require 'aeolus_client'
require 'logger'

# FIXME: get rid of these when refactoring config loading:
ActiveResource::Base.logger = Logger.new(STDOUT)
ActiveResource::Base.logger.level = Logger::INFO

module ActiveResource
class Errors
# Grabs errors from an XML response.
def from_xml(xml, save_cache = false)
array = Array.wrap(Hash.from_xml(xml)['errors']['error'])
# The below is added because the default behaviour (the above
# line) only works fine if the error string is not buried in
# another layer of xml.
#
# from_array (in this Errors class) is brittle and will blow up
# if it doesn't get an array of strings.
if array.size >= 1 && array[0].is_a?(Hash) &&
array[0].has_key?('message')
array.map! {|error| error['message']}
end
from_array array, save_cache
end
end
end

# declaring the namespace but for style reasons not including the Base
# class definition within the block (saving as much excessive
# indentation as possible)
module AeolusClient
end

class AeolusClient::Base < ActiveResource::Base
self.timeout = 600
self.format = :xml
Expand Down
2 changes: 2 additions & 0 deletions lib/aeolus_client/provider.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'aeolus_client/base'

class AeolusClient::ProviderXMLFormat
include ActiveResource::Formats::XmlFormat

Expand Down
2 changes: 2 additions & 0 deletions lib/aeolus_client/provider_account.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'aeolus_client/base'

class AeolusClient::ProviderAccountXMLFormat
include ActiveResource::Formats::XmlFormat

Expand Down
2 changes: 2 additions & 0 deletions lib/aeolus_client/provider_type.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'aeolus_client/base'

class AeolusClient::ProviderTypeXMLFormat
include ActiveResource::Formats::XmlFormat

Expand Down

0 comments on commit c501f73

Please sign in to comment.