summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormo khan <mo@mokhan.ca>2013-07-20 17:54:33 -0600
committermo khan <mo@mokhan.ca>2013-07-20 17:54:33 -0600
commit381c938ffb77feee283b74c03a7c928478d1a5bf (patch)
treeff97a1027cfb7a40e2d7b0a27e49c07aa772676b
parent70ceef5b0058e2ef35d2c787689e6cb2e931c057 (diff)
move equality check to entity and rename a couple of items to entity
-rw-r--r--Gemfile.lock2
-rw-r--r--lib/humble/mapping_configuration.rb6
-rw-r--r--lib/humble/result_set.rb2
-rw-r--r--lib/humble/session.rb8
-rw-r--r--spec/integration/fixtures/movie_mapping.rb7
5 files changed, 16 insertions, 9 deletions
diff --git a/Gemfile.lock b/Gemfile.lock
index 9fa4c42..d18c100 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
- humble (0.0.1374363779)
+ humble (0.0.1374364444)
sequel
GEM
diff --git a/lib/humble/mapping_configuration.rb b/lib/humble/mapping_configuration.rb
index 4ae59a7..a62d98c 100644
--- a/lib/humble/mapping_configuration.rb
+++ b/lib/humble/mapping_configuration.rb
@@ -9,12 +9,12 @@ module Humble
ResultSet.new(connection[@table.name], mapper)
end
- def save_using(connection, item)
- @table.persist(connection, item)
+ def save_using(connection, entity)
+ @table.persist(connection, entity)
end
def matches?(item)
- item == self[:type] || item.is_a?(self[:type])
+ self[:type] == item || item.is_a?(self[:type])
end
def [](key)
diff --git a/lib/humble/result_set.rb b/lib/humble/result_set.rb
index 9210f29..0a0d4ee 100644
--- a/lib/humble/result_set.rb
+++ b/lib/humble/result_set.rb
@@ -15,7 +15,7 @@ module Humble
def include?(item)
self.find do |x|
- x.id == item.id
+ x == item
end
end
diff --git a/lib/humble/session.rb b/lib/humble/session.rb
index 88ac8cc..be12157 100644
--- a/lib/humble/session.rb
+++ b/lib/humble/session.rb
@@ -11,8 +11,8 @@ module Humble
end
end
- def save(item)
- mapping_for(item).save_using(create_connection, item)
+ def save(entity)
+ mapping_for(entity).save_using(create_connection, entity)
end
def find_all(clazz)
@@ -27,8 +27,8 @@ module Humble
@connection ||= connection_factory.create_connection
end
- def mapping_for(item)
- mapper_registry.mapping_for(item)
+ def mapping_for(entity)
+ mapper_registry.mapping_for(entity)
end
end
end
diff --git a/spec/integration/fixtures/movie_mapping.rb b/spec/integration/fixtures/movie_mapping.rb
index b3e800d..cf727be 100644
--- a/spec/integration/fixtures/movie_mapping.rb
+++ b/spec/integration/fixtures/movie_mapping.rb
@@ -9,6 +9,13 @@ class Movie
def name=(new_name)
@name = new_name
end
+
+ def ==(other)
+ return false unless other
+ return false if other.id == -1
+ return false if @id == -1
+ @id == other.id
+ end
end
class MovieMapping < Humble::DatabaseMapping