Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename Generator#next to Generator#next_object_id. #17

Merged
merged 1 commit into from
Apr 1, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions ext/bson/native.c
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,6 @@ void Init_native()
rb_define_private_method(string, "check_for_illegal_characters!", rb_string_check_for_illegal_characters, 0);

// Redefine the next method on the object id generator.
rb_undef_method(generator, "next");
rb_define_method(generator, "next", rb_object_id_generator_next, -1);
rb_undef_method(generator, "next_object_id");
rb_define_method(generator, "next_object_id", rb_object_id_generator_next, -1);
}
8 changes: 4 additions & 4 deletions lib/bson/object_id.rb
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def marshal_load(data)
# @since 2.0.0
def to_bson(encoded = ''.force_encoding(BINARY))
repair if defined?(@data)
@raw_data ||= @@generator.next
@raw_data ||= @@generator.next_object_id
encoded << @raw_data
end

Expand Down Expand Up @@ -268,7 +268,7 @@ def from_string(string)
#
# @since 2.0.0
def from_time(time, options = {})
from_data(options[:unique] ? @@generator.next(time.to_i) : [ time.to_i ].pack("Nx8"))
from_data(options[:unique] ? @@generator.next_object_id(time.to_i) : [ time.to_i ].pack("Nx8"))
end

# Determine if the provided string is a legal object id.
Expand Down Expand Up @@ -337,14 +337,14 @@ def initialize
# object id counter. Will use the provided time if not nil.
#
# @example Get the next object id data.
# generator.next
# generator.next_object_id
#
# @param [ Time ] time The optional time to generate with.
#
# @return [ String ] The raw object id bytes.
#
# @since 2.0.0
def next(time = nil)
def next_object_id(time = nil)
@mutex.lock
begin
count = @counter = (@counter + 1) % 0xFFFFFF
Expand Down