lib/active_groonga/base.rb in activegroonga-1.0.0 vs lib/active_groonga/base.rb in activegroonga-1.0.1

- old
+ new

@@ -77,21 +77,36 @@ record = table[record_id] return nil if record.nil? instantiate(record) end - def select(options={}) - if block_given? - records = table.select do |record| - yield(record) - end - ResultSet.new(records, self, :expression => records.expression) + def exists?(record_id) + record_id = record_id.record_id if record_id.respond_to?(:record_id) + if table.support_key? + not table[record_id].nil? else - ResultSet.new(table, self) + begin + record_id = Integer(record_id) + rescue ArgumentError + return false + end + table.exist?(record_id) end end + def select(options={}) + return all(options) unless block_given? + records = table.select do |record| + yield(record) + end + ResultSet.new(records, self, :expression => records.expression) + end + + def all(options={}) + ResultSet.new(table, self) + end + def count table.size end def context @@ -234,9 +249,13 @@ end end def record_raw_id id + end + + def to_key + persisted? ? [record_id] : nil end def attributes @attributes end