Skip to content

Commit

Permalink
* removed method overrides used to strip .xml from activeresource def…
Browse files Browse the repository at this point in the history
…ault urls as ITSTs Finn Jordal changed the API for us -- yippeee!

* shaved down the instantiate_collection method

git-svn-id: http://oiorest.googlecode.com/svn/trunk@4 ce39abd0-6649-0410-85e9-6d4393f8d017
  • Loading branch information
[email protected] committed Apr 2, 2008
1 parent 675d124 commit 09d5c2d
Showing 1 changed file with 18 additions and 44 deletions.
62 changes: 18 additions & 44 deletions active_oio.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,58 +3,32 @@

class ActiveOIO < ActiveResource::Base
self.site = 'http://oiorest.dk/danmark/'

class << self

## remove .xml from the url
def element_path(id, prefix_options = {}, query_options = nil)
prefix_options, query_options = split_options(prefix_options) if query_options.nil?
"#{prefix(prefix_options)}#{collection_name}/#{id}#{query_string(query_options)}"
end

## Remove .xml from the url.
def collection_path(prefix_options = {}, query_options = nil)
prefix_options, query_options = split_options(prefix_options) if query_options.nil?
"#{prefix(prefix_options)}#{collection_name}#{query_string(query_options)}"
end
## enable logger to see request/response in STDOUT
#self.logger = Logger.new(STDOUT)

class << self


## this method override makes it possible to retrieve arrays of results
def instantiate_collection(collection, prefix_options = {})
if collection.is_a? Array
collection.collect! { |record| instantiate_record(record, prefix_options) }
elsif collection.is_a? Hash
# debugger
if collection.size == 3
value = collection.values[1]
if value.is_a? Array
# Assume the value contains an array of elements to create
return value.collect! { |record| instantiate_record(record, prefix_options) }
elsif value.is_a? Hash
# Assume the value contains a single row result
result = []
result << instantiate_record(value, prefix_options)
else
raise ArgumentError("Expected a nested Array or Hash but got #{value.inspect}")
end
else
# Assume the result was a single row, so encapsulate it in an array
result = []
result << instantiate_record(collection, prefix_options)
return result
end
elsif
raise ArgumentError, "Expected an Array or Hash, but got #{collection.inspect}"
if collection.size == 3 # collection with timestamps
value = collection.values[1]
elsif collection.size == 2 # collection without timestamp
value = collection.values[0]
end
# Assume the value contains an array of elements to create
return value.collect! { |record| instantiate_record(record, prefix_options) }
end

end
end

## Inflections for OIO
Inflector.inflections do |inflect|
inflect.irregular 'postdistrikt', 'postdistrikter'
inflect.irregular 'sogn', 'sogne'
inflect.irregular 'kommune', 'kommuner'
inflect.irregular 'region', 'regioner'
end
inflect.irregular 'postdistrikt', 'postdistrikter'
inflect.irregular 'sogn', 'sogne'
inflect.irregular 'kommune', 'kommuner'
inflect.irregular 'region', 'regioner'
inflect.irregular 'skole', 'skoler'
inflect.irregular 'lokalitet', 'lokaliteter'

end

0 comments on commit 09d5c2d

Please sign in to comment.