factis 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -104,6 +104,11 @@ recall_fact(:some_foo)
104
104
  => #<Foo:0x007ffd84394728>
105
105
  ```
106
106
 
107
+ ## Formal Documentation ##
108
+
109
+ The actual library docs can be read
110
+ [over on rubydoc](http://rubydoc.info/gems/factis/frames).
111
+
107
112
  ## Contributing ##
108
113
 
109
114
  Do you use git-flow? I sure do. Please base anything you do off of
@@ -1,27 +1,66 @@
1
1
  require 'factis/memory'
2
2
 
3
+ # This module contains syntactic sugar for the methods in Factis::Memory.
4
+ # The purpose is, basically, to make the methods easily injected into,
5
+ # say, Cucumber via extend.
6
+
3
7
  module Factis
4
8
 
9
+ # Forget all of the known facts
10
+ # @see Factis::Memory.reset!
11
+
5
12
  def clear_all_facts!
6
13
  Factis::Memory.reset!
7
14
  end
8
15
 
16
+ # Returns the entire facts hash
17
+ # @return [Hash] the facts hash
18
+ # @see Factis::Memory.all_facts
19
+
9
20
  def all_facts
10
21
  Factis::Memory.all_facts
11
22
  end
12
23
 
24
+ # Memorize the given content, keyed by the given fact key. This wrapper
25
+ # does not allow for overwriting of a fact, and an atttempt to do so will
26
+ # raise an error.
27
+ # @param fact a key suitable for use in a Hash
28
+ # @param content (Object) the content to store
29
+ # @return [Object] the content that was stored
30
+ # @raise [RuntimeError] if the fact key is already in the facts hash
31
+ # @see Factis::Memory.memorize
32
+
13
33
  def memorize_fact(fact, content)
14
34
  Factis::Memory.memorize(fact, content)
15
35
  end
16
36
 
37
+ # This method is equivalent to memorize_fact in all ways, save that it
38
+ # disregards the possible existence of the fact key within the internal
39
+ # hash.
40
+ # @note This undermines the goal of *safely* tracking state. Please refrain
41
+ # from using it if at all possible.
42
+ # @see Factis#memorize_fact
43
+ # @see Factis::Memory.memorize
44
+
17
45
  def indifferently_memorize_fact(fact, content)
18
46
  Factis::Memory.memorize(fact, content, :overwrite => true)
19
47
  end
20
48
 
49
+ # Get fact content by key, raising an error for an unknown fact
50
+ # @param fact the key of the fact to retrieve
51
+ # @return [Object] the content of the recalled fact
52
+ # @raise [RuntimeError] if the key is not in the fact hash
53
+
21
54
  def recall_fact(fact)
22
55
  Factis::Memory.recall(fact)
23
56
  end
24
57
 
58
+ # Removes the given fact (key) from internal storage, raising an error for
59
+ # an unknown fact
60
+ # @param fact the key of the fact to remove
61
+ # @return [Object] the content of the removed fact
62
+ # @raise [RuntimeError] if the key is not in the fact hash
63
+
25
64
  def forget_fact(fact)
26
65
  Factis::Memory.forget(fact)
27
66
  end
@@ -1,16 +1,35 @@
1
1
  module Factis
2
2
  class Memory
3
3
 
4
- def self.init_memory!
5
- @facts = Hash.new
4
+ class << self
5
+ private
6
+ def init_memory!
7
+ @facts = Hash.new
8
+ end
6
9
  end
7
10
 
11
+ # Get the entire facts hash
12
+ #
13
+ # @return [Hash] all facts that have been stored
14
+
8
15
  def self.all_facts
9
16
  init_memory! if @facts.nil?
10
17
  @facts
11
18
  end
12
19
 
13
- def self.memorize(fact, content, options = {})
20
+ # Stores content as fact, optionally overwriting said content
21
+ #
22
+ # @param fact the key for the fact hash
23
+ # @param content [Object] the content for the fact
24
+ # @param options [Hash] The only key checked is :overwrite
25
+ # a boolean defaulting to false.
26
+ #
27
+ # @return [Object] the fact content
28
+ #
29
+ # @raise [RuntimeError] if the fact key is already known and :overwrite
30
+ # is not active.
31
+
32
+ def self.memorize(fact, content, options = {:overwrite => false})
14
33
  init_memory! if @facts.nil?
15
34
  if known_fact?(fact)
16
35
  unless options[:overwrite] == true
@@ -20,11 +39,25 @@ module Factis
20
39
  @facts[fact] = content
21
40
  end
22
41
 
42
+ # Determines if the given fact key is already known
43
+ #
44
+ # @param fact the fact key to check
45
+ #
46
+ # @return [Boolean] true if the key is known, false otherwise
47
+
23
48
  def self.known_fact?(fact)
24
49
  init_memory! if @facts.nil?
25
50
  @facts.keys.include?(fact)
26
51
  end
27
52
 
53
+ # Removes the given fact (key) from internal storage
54
+ #
55
+ # @param fact the key of the fact to remove
56
+ #
57
+ # @return [Object] the content of the removed fact
58
+ #
59
+ # @raise [RuntimeError] if the key is not in the fact hash
60
+
28
61
  def self.forget(fact)
29
62
  init_memory! if @facts.nil?
30
63
  unless known_fact?(fact)
@@ -33,6 +66,14 @@ module Factis
33
66
  @facts.delete(fact)
34
67
  end
35
68
 
69
+ # Get fact content by key
70
+ #
71
+ # @param fact the key of the fact to retrieve
72
+ #
73
+ # @return [Object] the content of the recalled fact
74
+ #
75
+ # @raise [RuntimeError] if the key is not in the fact hash
76
+
36
77
  def self.recall(fact)
37
78
  init_memory! if @facts.nil?
38
79
  unless known_fact?(fact)
@@ -41,6 +82,8 @@ module Factis
41
82
  @facts[fact]
42
83
  end
43
84
 
85
+ # Clear the entire facts hash
86
+
44
87
  def self.reset!
45
88
  init_memory! if @facts.nil?
46
89
  @facts.clear
@@ -1,3 +1,3 @@
1
1
  module Factis
2
- VERSION = '0.0.7'
2
+ VERSION = '0.0.8'
3
3
  end
@@ -93,7 +93,7 @@ describe Factis::Memory do
93
93
  describe %{.init_memory!} do
94
94
  it %{should instantiate a new Hash for the memory} do
95
95
  old = memory.all_facts.__id__
96
- memory.init_memory!
96
+ memory.class_eval('init_memory!')
97
97
  memory.all_facts.__id__.should_not == old
98
98
  end
99
99
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: factis
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-10-07 00:00:00.000000000 Z
12
+ date: 2013-10-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -82,3 +82,4 @@ test_files:
82
82
  - spec/factis/memory_spec.rb
83
83
  - spec/factis_spec.rb
84
84
  - spec/spec_helper.rb
85
+ has_rdoc: