temporal_object 0.0.3 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- temporal_object (0.0.2)
4
+ temporal_object (0.1.0)
5
5
  time_span
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -1,6 +1,16 @@
1
1
  Temporal Object
2
2
  ===============
3
3
 
4
+ This gem is implemented as a mixin, so that you can do the following:
5
+
6
+ ```ruby
7
+ require 'temporal_object'
8
+ include TemporalObject
9
+ ```
10
+
11
+ Will add instance methods to manipulate TimeLines (and thereby TimeSpans and RelativeTimes) to the including object.
12
+
13
+
4
14
  Most of the temporal aspects for Temporal Object are delegated to TimeSpan. The Temporal Object just has any number of
5
15
  TimeSpan statuses.
6
16
 
@@ -9,3 +19,6 @@ TimeSpan statuses.
9
19
  * [rdoc] (http://rubydoc.info/gems/time_span/0.0.3/frames)
10
20
  * [github] (https://github.com/coyote/time_span)
11
21
  * [rubygems] (https://rubygems.org/gems/time_span)
22
+
23
+
24
+ Note, that this implementation is quite changed from gem version 0.0.3, where TemporalObjects needed to be created, which pointed to your actual object. Code has been simplified thereby, and is much cleaner.
@@ -1,57 +1,39 @@
1
1
  require 'temporal_object/version'
2
2
  require 'time_span'
3
3
 
4
+
4
5
  # @author Craig A. Cook
5
6
  module TemporalObject
6
7
 
7
- # @author Craig A. Cook
8
- class TemporalObject
9
-
10
- # [Array] of TimeSpan::TimeLine statuses for temporal attributes
11
- attr_accessor :statuses
12
- # [String] object human readable identifier
13
- attr_accessor :name
14
- # [Object] associated Ruby Object of any kind
15
- attr_accessor :reference_object # arbitrary Ruby object associated.
16
-
17
-
18
- ## must be able to:
19
- #===============================
20
- # -- add, remove a timeline
21
- # -- erase all timelines, all statuses from a timeline
22
- # -- remove all timelines
23
-
24
- # @param [String] nom is the TemporalObject's name
25
- # @param [Object] reference_obj is the object associated with this TemporalObject
26
- def initialize(nom="", reference_obj=Object.new)
27
- @statuses = [] # Array of TimeSpan::TimeLine
28
- @name = ""
29
- @reference_object = reference_obj
30
- end
31
-
32
- # add a timeline to the TemporalObject
33
- # @param [TimeSpan::TimeLine] timeline added to the object
34
- # @return [Array] adjusted list of timelines if no exception raised.
35
- def add_timeline(timeline)
36
- raise ArgumentError, "Can only add a TimeSpan::TimeLine to a TemporalObject's statuses" unless timeline.kind_of? TimeSpan::TimeLine
37
- @statuses << timeline
38
- end
39
-
40
- # remove all TimeLine s from the TemporalObject
41
- # @return [Array] the associated timelines
42
- def remove_timelines
43
- @statuses = []
44
- end
45
-
46
- # delete the cited timeline
47
- # @param timeline [TimeSpan::TimeLine] timeline to delete
48
- # @raise ArgumentError if called with a non-TimeLine object
49
- # @return [TimeSpan::TimeLine, nil] TimeLIne deleted if successful or nil if not
50
- def remove_timeline(timeline)
51
- raise ArgumentError, "Can only remove a TimeLine with this call." unless timeline.kind_of? TimeSpan::TimeLine
52
- @statuses.delete(timeline)
53
- end
8
+ # [Array] of TimeSpan::TimeLine statuses for temporal attributes
9
+ attr_accessor :temporal_statuses
10
+
11
+ def initialize
12
+ super
13
+ @temporal_statuses = [] # Array of TimeSpan::TimeLine
14
+ end
15
+
16
+ # add a timeline to the TemporalObject
17
+ # @param [TimeSpan::TimeLine] timeline added to the object
18
+ # @return [Array] adjusted list of timelines if no exception raised.
19
+ def add_timeline(timeline)
20
+ raise ArgumentError, "Can only add a TimeSpan::TimeLine to a TemporalObject's statuses" unless timeline.kind_of? TimeSpan::TimeLine
21
+ @temporal_statuses << timeline
22
+ end
23
+
24
+ # remove all TimeLine s from the TemporalObject
25
+ # @return [Array] the associated timelines
26
+ def remove_timelines
27
+ @temporal_statuses = []
28
+ end
54
29
 
30
+ # delete the cited timeline
31
+ # @param timeline [TimeSpan::TimeLine] timeline to delete
32
+ # @raise ArgumentError if called with a non-TimeLine object
33
+ # @return [TimeSpan::TimeLine, nil] TimeLIne deleted if successful or nil if not
34
+ def remove_timeline(timeline)
35
+ raise ArgumentError, "Can only remove a TimeLine with this call." unless timeline.kind_of? TimeSpan::TimeLine
36
+ @temporal_statuses.delete(timeline)
55
37
  end
56
38
 
57
39
  end
@@ -1,4 +1,3 @@
1
1
  module TemporalObject
2
- VERSION = "0.0.3"
3
-
2
+ VERSION = "0.1.0"
4
3
  end
@@ -1,9 +1,16 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '../../spec_helper')
2
2
 
3
+ # functionality is defined as a mixin, not an Object, so
4
+ # here we create a mock class for testing the temporal_object mixin gem
5
+ class TemporalObjectTester < Object
6
+ require 'temporal_object'
7
+ include TemporalObject
8
+ end
9
+
3
10
  describe "TemporalObject" do
4
11
 
5
12
  let (:temporal_object) do
6
- TemporalObject::TemporalObject.new "Temporal Test Object"
13
+ TemporalObjectTester.new
7
14
  end
8
15
 
9
16
  let (:timeline) do
@@ -14,17 +21,35 @@
14
21
  TimeSpan::TimeLine.new "second test TimeLine"
15
22
  end
16
23
 
24
+ context "TemporalObject" do
17
25
 
18
- context "TemporalObject::TemporalObject" do
26
+ context "added #instance methods" do
19
27
 
20
- context "#instance methods" do
28
+ context "initial state" do
21
29
 
22
- context "Initial state" do
23
30
  it "should have no timelines" do
24
- temporal_object.statuses.should be_empty
31
+ temporal_object.temporal_statuses.should be_empty
32
+ end
33
+
34
+ end
35
+
36
+ context "methods defined" do
37
+
38
+ it "should respond_to? remove_timelines" do
39
+ temporal_object.should respond_to :remove_timelines
40
+ end
41
+
42
+ it "should respond_to? add_timeline (some_timeline)" do
43
+ temporal_object.should respond_to(:add_timeline)
25
44
  end
45
+
46
+ it "should respond_to? remove_time" do
47
+ temporal_object.should respond_to(:remove_timeline)
48
+ end
49
+
26
50
  end
27
51
 
52
+
28
53
  context "TimeSpan::TimeLine manipulations" do
29
54
 
30
55
  before (:each) do
@@ -32,23 +57,32 @@
32
57
  end
33
58
 
34
59
  it "can add a TimeLine to the TemporalObject" do
35
- temporal_object.statuses.should_not be_empty, "TemporalObject::TimeLine not present."
60
+ temporal_object.temporal_statuses.should_not be_empty, "TemporalObject::TimeLine not present."
36
61
  end
37
62
 
63
+ it "should not allow adding a non-timeline object to the temporal statuses" do
64
+ lambda { temporal_object.add_timeline "foo"}.should raise_error ArgumentError
65
+ end
66
+
67
+
38
68
  it "can remove a given timeline from the temporal object" do
39
69
  temporal_object.add_timeline timeline2
40
70
  temporal_object.remove_timeline timeline
41
- temporal_object.statuses.should_not be_empty #, "TemporalObject::TimeLine does not have 1 status when it should."
71
+ temporal_object.temporal_statuses.should_not be_empty #, "TemporalObject::TimeLine does not have 1 status when it should."
72
+ end
73
+
74
+ it "should not accept a non-timeline for removal from temporal statuses" do
75
+ lambda { temporal_object.remove_timeline "foo" }.should raise_error, ArgumentError
42
76
  end
43
77
 
44
78
  it "can remove a given timeline from the temporal object" do
45
79
  temporal_object.remove_timeline timeline
46
- temporal_object.statuses.should be_empty #, "TemporalObject::TimeLine does not have 1 status when it should."
80
+ temporal_object.temporal_statuses.should be_empty #, "TemporalObject::TimeLine does not have 1 status when it should."
47
81
  end
48
82
 
49
83
  it "can remove all timelines from the TemporalObject" do
50
84
  temporal_object.remove_timelines
51
- temporal_object.statuses.should be_empty
85
+ temporal_object.temporal_statuses.should be_empty
52
86
  end
53
87
 
54
88
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: temporal_object
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-06 00:00:00.000000000 Z
12
+ date: 2012-03-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &72897120 !ruby/object:Gem::Requirement
16
+ requirement: &85683880 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *72897120
24
+ version_requirements: *85683880
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: time_span
27
- requirement: &72896910 !ruby/object:Gem::Requirement
27
+ requirement: &85683570 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *72896910
35
+ version_requirements: *85683570
36
36
  description: Martin Fowler\'s Temporal Object Pattern. Use time_span gem for the
37
37
  times.
38
38
  email: