Permalink
Browse files

Refactoring: Replaced get_item_from_id with get_items_from_id

  • Loading branch information...
1 parent 296175f commit 3e8e14f15d5b9043b50af338485d2b74ab5ccee1 Makoto Inoue committed Nov 10, 2008
Showing with 10 additions and 7 deletions.
  1. +10 −7 lib/tc_adapter.rb
View
@@ -46,7 +46,7 @@ def read_many(query)
operator, property, value = query.conditions.first
if property.name == :id # Model.get
- results = [get_item_from_id(query, value)]
+ results = get_items_from_id(query, value)
else # Model.first w argument
case operator
when :eql
@@ -94,7 +94,7 @@ def read_one(query)
operator, property, value = query.conditions.first
if property.name == :id # Model.get
- results = [get_item_from_id(query, value)]
+ results = get_items_from_id(query, value)
else # Model.first w argument
case operator
when :eql
@@ -107,7 +107,7 @@ def read_one(query)
else
raise NotImplementedError("#{operator} is not implmented yet")
end
- results = [get_item_from_id(query, item_id)]
+ results = get_items_from_id(query, item_id)
end
else # Model.first w/o argument
data = access_data(query.model) do |item|
@@ -121,8 +121,11 @@ def read_one(query)
end
end
- data = results.first unless results.size == 0
-
+ if results.class == Array
+ data = results.first
+ else
+ data = results
+ end
if data
data = query.fields.map do |property|
data[property.field.to_sym]
@@ -194,10 +197,10 @@ def get_item_from_id(query, value)
# Marshal.load(raw_data)
# end
# end
- # p "get_item_from_id: #{result.inspect}"
+ # p "get_items_from_id: #{result.inspect}"
end
- # TODO: Refactor to consolidate with get_item_from_id method
+ # TODO: Refactor to consolidate with get_items_from_id method
def get_items_from_id(query, values)
result = values.to_a.map do |value|

0 comments on commit 3e8e14f

Please sign in to comment.