Class: FakeDynamo::Sack

Inherits:
Object
  • Object
show all
Defined in:
lib/fake_dynamo/sack.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(max_size = 1 * 1024 * 1024) ⇒ Sack

1 mb



5
6
7
8
# File 'lib/fake_dynamo/sack.rb', line 5

def initialize(max_size = 1 * 1024 * 1024) # 1 mb
  @size = 0
  @max_size = max_size
end

Instance Attribute Details

#itemObject

Returns the value of attribute item.



3
4
5
# File 'lib/fake_dynamo/sack.rb', line 3

def item
  @item
end

#max_sizeObject

Returns the value of attribute max_size.



3
4
5
# File 'lib/fake_dynamo/sack.rb', line 3

def max_size
  @max_size
end

#sizeObject

Returns the value of attribute size.



3
4
5
# File 'lib/fake_dynamo/sack.rb', line 3

def size
  @size
end

Instance Method Details

#add(item) ⇒ Object



10
11
12
# File 'lib/fake_dynamo/sack.rb', line 10

def add(item)
  @size += item.to_json.bytesize
end

#has_space?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/fake_dynamo/sack.rb', line 14

def has_space?
  @size < @max_size
end