Class: PositronicBrain::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/positronic_brain/base.rb

Direct Known Subclasses

Classifier::Base

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(namespace, options = {}) ⇒ Base

Returns a new instance of Base.



8
9
10
11
# File 'lib/positronic_brain/base.rb', line 8

def initialize(namespace, options = {})
  @namespace   = namespace
  @persistence = self.class.initialize_persistence(dump_path, options[:persistence] || {})
end

Class Attribute Details

.dump_nameObject



25
26
27
# File 'lib/positronic_brain/base.rb', line 25

def dump_name
  @dump_name || self.name.gsub(/^.*\:\:/, '').underscore
end

.dump_pathObject



29
30
31
# File 'lib/positronic_brain/base.rb', line 29

def dump_path
  @dump_path || self.superclass.dump_path
end

Instance Attribute Details

#namespaceObject (readonly)

Returns the value of attribute namespace.



3
4
5
# File 'lib/positronic_brain/base.rb', line 3

def namespace
  @namespace
end

#persistenceObject

Returns the value of attribute persistence.



4
5
6
# File 'lib/positronic_brain/base.rb', line 4

def persistence
  @persistence
end

Class Method Details

.initialize_persistence(path, options = {}) ⇒ Object



45
46
47
# File 'lib/positronic_brain/base.rb', line 45

def initialize_persistence(path, options = {})
  persistence_class.new path, persistence_options.merge(options)
end

.persistence(klass, options = {}) ⇒ Object



41
42
43
# File 'lib/positronic_brain/base.rb', line 41

def persistence(klass, options = {})
  @persistence_class, @persistence_options = klass, options
end

.persistence_classObject



33
34
35
# File 'lib/positronic_brain/base.rb', line 33

def persistence_class
  @persistence_class || self.superclass.persistence_class
end

.persistence_optionsObject



37
38
39
# File 'lib/positronic_brain/base.rb', line 37

def persistence_options
  @persistence_options || self.superclass.persistence_options
end

Instance Method Details

#dump_pathObject



13
14
15
16
# File 'lib/positronic_brain/base.rb', line 13

def dump_path
  path_parts = [self.class.dump_path, self.class.dump_name, "#{@namespace}.marshal"].compact
  File.join *path_parts
end

#inspectObject



18
19
20
# File 'lib/positronic_brain/base.rb', line 18

def inspect
  "#<#{self.class.name} #{namespace}>"
end