Class: Soup

Inherits:
Object
  • Object
show all
Defined in:
lib/soup/empty_class.rb,
lib/soup.rb,
lib/soup/snip.rb,
lib/soup/backends.rb,
lib/soup/test_helper.rb,
lib/soup/backends/base.rb,
lib/soup/backends/memory.rb,
lib/soup/backends/read_only.rb,
lib/soup/backends/multi_soup.rb,
lib/soup/backends/file_backend.rb,
lib/soup/backends/yaml_backend.rb

Overview

Based on Builder’s BlankSlate object

Defined Under Namespace

Modules: Backends, TestHelper Classes: BackendIncompatibleError, EmptyClass, Snip

Instance Method Summary collapse

Constructor Details

#initialize(backend = nil) ⇒ Soup

Get the soup ready!



15
16
17
18
19
# File 'lib/soup.rb', line 15

def initialize(backend=nil)
  @backend = backend || Soup::Backends::FileBackend.new
  check_backend_for_compatibility
  @backend.prepare
end

Instance Method Details

#<<(attributes) ⇒ Object

Puts some data into the soup, and returns an object that contains that data. The object should respond to accessing and setting its attributes as if they were defined using attr_accessor on the object’s class.



35
36
37
# File 'lib/soup.rb', line 35

def <<(attributes)
  @backend.save_snip(symbolize_keys(attributes))
end

#[](conditions) ⇒ Object

A shorthand for #with, with the addition that only a name may be supplied (i.e. soup[‘my snip’])



26
27
28
29
# File 'lib/soup.rb', line 26

def [](conditions)
  conditions = {:name => conditions} unless conditions.respond_to?(:keys)
  with(conditions)
end

#all_snipsObject



51
52
53
# File 'lib/soup.rb', line 51

def all_snips
  @backend.all_snips
end

#destroy(name) ⇒ Object



47
48
49
# File 'lib/soup.rb', line 47

def destroy(name)
  @backend.destroy(name)
end

#with(conditions) ⇒ Object

Finds bits in the soup that make the given attribute hash. This method should eventually be delegated to the underlying persistence layers (i.e. Snips and Tuples, or another document database). The expected behaviour is



43
44
45
# File 'lib/soup.rb', line 43

def with(conditions)
  @backend.find(symbolize_keys(conditions))
end