Class: Aerospike::Filter

Inherits:
Object
  • Object
show all
Defined in:
lib/aerospike/query/filter.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#packed_ctxObject (readonly)

Returns the value of attribute packed_ctx.



19
20
21
# File 'lib/aerospike/query/filter.rb', line 19

def packed_ctx
  @packed_ctx
end

Class Method Details

.contains(bin_name, value, col_type, ctx: nil) ⇒ Object Also known as: Contains



27
28
29
# File 'lib/aerospike/query/filter.rb', line 27

def contains(bin_name, value, col_type, ctx: nil)
  Filter.new(bin_name, value, value, nil, col_type, ctx)
end

.equal(bin_name, value, ctx: nil) ⇒ Object Also known as: Equal



23
24
25
# File 'lib/aerospike/query/filter.rb', line 23

def equal(bin_name, value, ctx: nil)
  Filter.new(bin_name, value, value, nil, nil, ctx)
end

.geo_contains_geo_point(bin_name, point, col_type = nil, ctx: nil) ⇒ Object Also known as: geoContainsGeoJSONPoint



45
46
47
48
# File 'lib/aerospike/query/filter.rb', line 45

def geo_contains_geo_point(bin_name, point, col_type = nil, ctx: nil)
  point = point.to_json
  Filter.new(bin_name, point, point, ParticleType::GEOJSON, col_type, ctx)
end

.geo_contains_point(bin_name, lon, lat, col_type = nil, ctx: nil) ⇒ Object Also known as: geoContainsPoint



50
51
52
53
# File 'lib/aerospike/query/filter.rb', line 50

def geo_contains_point(bin_name, lon, lat, col_type = nil, ctx: nil)
  point = GeoJSON.new({ type: "Point", coordinates: [lon, lat] })
  geo_contains_geo_point(bin_name, point, col_type, ctx: ctx)
end

.geo_within_geo_region(bin_name, region, col_type = nil, ctx: nil) ⇒ Object Also known as: geoWithinGeoJSONRegion



35
36
37
38
# File 'lib/aerospike/query/filter.rb', line 35

def geo_within_geo_region(bin_name, region, col_type = nil, ctx: nil)
  region = region.to_json
  Filter.new(bin_name, region, region, ParticleType::GEOJSON, col_type, ctx)
end

.geo_within_radius(bin_name, lon, lat, radius_meter, col_type = nil, ctx: nil) ⇒ Object Also known as: geoWithinRadius



40
41
42
43
# File 'lib/aerospike/query/filter.rb', line 40

def geo_within_radius(bin_name, lon, lat, radius_meter, col_type = nil, ctx: nil)
  region = GeoJSON.new({ type: "AeroCircle", coordinates: [[lon, lat], radius_meter] })
  geo_within_geo_region(bin_name, region, col_type, ctx: ctx)
end

.range(bin_name, from, to, col_type = nil, ctx: nil) ⇒ Object Also known as: Range



31
32
33
# File 'lib/aerospike/query/filter.rb', line 31

def range(bin_name, from, to, col_type = nil, ctx: nil)
  Filter.new(bin_name, from, to, nil, col_type, ctx)
end

Instance Method Details

#collection_typeObject

for internal use



93
94
95
96
97
98
99
100
101
# File 'lib/aerospike/query/filter.rb', line 93

def collection_type
  case @col_type
  when :default then 0
  when :list then 1
  when :mapkeys then 2
  when :mapvalues then 3
  else 0
  end
end

#estimate_sizeObject



65
66
67
# File 'lib/aerospike/query/filter.rb', line 65

def estimate_size
  return @name.bytesize + @begin.estimate_size + @end.estimate_size + 10
end

#to_sObject

Show the filter as String. This is util to show filters in logs.



106
107
108
109
# File 'lib/aerospike/query/filter.rb', line 106

def to_s
  return "#{@name} = #{@begin}" if @begin == @end
  "#{@name} = #{@begin} - #{@end}"
end

#write(buf, offset) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/aerospike/query/filter.rb', line 69

def write(buf, offset)
  # Write name.
  len = buf.write_binary(@name, offset + 1)
  buf.write_byte(len, offset)
  offset += len + 1

  # Write particle type.
  buf.write_byte(@val_type, offset)
  offset += 1

  # Write filter begin.
  len = @begin.write(buf, offset + 4)
  buf.write_int32(len, offset)
  offset += len + 4

  # Write filter end.
  len = @end.write(buf, offset + 4)
  buf.write_int32(len, offset)
  offset += len + 4

  offset
end