Class: ParserAction::BSON

Inherits:
Ruby show all
Defined in:
lib/ejson/parser_action/bson.rb

Constant Summary collapse

NUMBER_TO_TYPE =
{
  0   => :generic,
  1   => :function,
  2   => :old,
  3   => :uuid_old,
  4   => :uuid,
  5   => :md5,
  128 => :user,
}.freeze

Constants inherited from Ruby

Ruby::UNICODE_ESCAPER

Instance Method Summary collapse

Methods inherited from Ruby

#make_array, #make_date, #make_empty_array, #make_empty_object, #make_false, #make_identifier, #make_null, #make_number, #make_number_as_string, #make_number_long, #make_numeric_string, #make_object, #make_pair, #make_regexp, #make_root, #make_string, #make_true

Methods included from AbstractMongo

#make_date, #make_number_long, #make_regexp

Methods included from AbstractJSON

#make_array, #make_empty_array, #make_empty_object, #make_false, #make_identifier, #make_null, #make_number, #make_object, #make_pair, #make_root, #make_string, #make_true

Instance Method Details

#make_bin_data(_input, _starts_at, _ends_at, elements) ⇒ Object



21
22
23
24
25
26
27
28
# File 'lib/ejson/parser_action/bson.rb', line 21

def make_bin_data(_input, _starts_at, _ends_at, elements)
  data = elements.last
  type = elements.first

  type = NUMBER_TO_TYPE[type] if type.is_a? Numeric

  ::BSON::Binary.new(data, type.to_sym)
end

#make_db_ref(_input, _starts_at, _ends_at, elements) ⇒ Object



40
41
42
43
44
45
# File 'lib/ejson/parser_action/bson.rb', line 40

def make_db_ref(_input, _starts_at, _ends_at, elements)
  {
    "$ref": elements.first,
    "$id":  elements.last,
  }
end

#make_max_key(_input, _starts_at, _ends_at) ⇒ Object



51
52
53
# File 'lib/ejson/parser_action/bson.rb', line 51

def make_max_key(_input, _starts_at, _ends_at)
  ::BSON::MaxKey
end

#make_min_key(_input, _starts_at, _ends_at) ⇒ Object



47
48
49
# File 'lib/ejson/parser_action/bson.rb', line 47

def make_min_key(_input, _starts_at, _ends_at)
  ::BSON::MinKey
end

#make_number_decimal(_input, _starts_at, _ends_at, elements) ⇒ Object



34
35
36
37
38
# File 'lib/ejson/parser_action/bson.rb', line 34

def make_number_decimal(_input, _starts_at, _ends_at, elements)
  value = elements.first

  ::BSON::Decimal128.new(value.to_s)
end

#make_object_id(_input, _starts_at, _ends_at, elements) ⇒ Object



5
6
7
8
9
# File 'lib/ejson/parser_action/bson.rb', line 5

def make_object_id(_input, _starts_at, _ends_at, elements)
  value = elements.first

  ::BSON::ObjectId.from_string(value)
end

#make_timestamp(_input, _starts_at, _ends_at, elements) ⇒ Object



30
31
32
# File 'lib/ejson/parser_action/bson.rb', line 30

def make_timestamp(_input, _starts_at, _ends_at, elements)
  ::BSON::Timestamp.new(elements.first, elements.last)
end

#make_undefined(_input, _starts_at, _ends_at) ⇒ Object



55
56
57
# File 'lib/ejson/parser_action/bson.rb', line 55

def make_undefined(_input, _starts_at, _ends_at)
  ::BSON::Undefined
end