juncture 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d6d2a7c30fe31a9d2546027a5d54c7e9408cb3c3
4
+ data.tar.gz: 30cbde17db14053e6b988e6a4ffb1beba2e4c217
5
+ SHA512:
6
+ metadata.gz: a7df57354b19319d741bb27280d313a810d4776cbb84ea693255ab8bb0d6306614bffa973f2baaf8ffd45488e864668fe8685494dfe2563a1ff8002fb784ddba
7
+ data.tar.gz: 19722144048c8d7223b2b30cafe0b79be4bad11bfc953566223127afbd04563f6a28c9c305375a639569376c4951edcaa448fd79392db1bfee24d8f72ba75b82
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 Ben Slaughter
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,4 @@
1
+ juncture
2
+ ========
3
+
4
+ A simple state object that can be queried
@@ -0,0 +1,4 @@
1
+ class Juncture
2
+ VERSION = "0.1.0".freeze
3
+ DATE = "2014-02-04".freeze
4
+ end
data/lib/juncture.rb ADDED
@@ -0,0 +1,57 @@
1
+ class Juncture
2
+ def initialize *states, **kwargs
3
+ @states = states
4
+ @current_state = kwargs[:default]
5
+ end
6
+
7
+ def method_missing meth, *args, &block
8
+ if @states.respond_to? meth
9
+ @states.send meth, *args, &block
10
+ else
11
+ super
12
+ end
13
+ end
14
+
15
+ def inspect
16
+ "#<Juncture:%s State:%s>" % [(object_id << 1).to_s(16), @current_state]
17
+ end
18
+
19
+ def state
20
+ @current_state
21
+ end
22
+
23
+ def set(new_state)
24
+ raise "UNKNOWN STATE: %s" % new_state unless @states.include? new_state
25
+ @current_state = new_state
26
+ end
27
+
28
+ def ==(value)
29
+ @current_state == value
30
+ end
31
+
32
+ def ===(value)
33
+ @current_state === value
34
+ end
35
+
36
+ def <(value)
37
+ @states[index+1..-1].include? value
38
+ end
39
+
40
+ def <=(value)
41
+ @states[index..-1].include? value
42
+ end
43
+
44
+ def >(value)
45
+ @states[0..index-1].include? value
46
+ end
47
+
48
+ def >=(value)
49
+ @states[0..index].include? value
50
+ end
51
+
52
+ private
53
+
54
+ def index
55
+ @states.index(@current_state)
56
+ end
57
+ end
@@ -0,0 +1,129 @@
1
+ require 'spec_helper'
2
+
3
+ describe Juncture do
4
+ it 'should be an instance of Class' do
5
+ expect(Juncture).to be_an_instance_of Class
6
+ end
7
+
8
+ describe '::new' do
9
+ it 'creates a new instance of Juncture' do
10
+ expect(Juncture.new []).to be_an_instance_of Juncture
11
+ end
12
+ end
13
+
14
+ describe '#inspect' do
15
+ it 'returns the Juncture object' do
16
+ expect(Juncture.new([]).inspect).to match(/<Juncture:\S+ State:\S*>/)
17
+ end
18
+ end
19
+
20
+ describe '#state' do
21
+ it 'returns the current state' do
22
+ temp = Juncture.new 1, 2, 3
23
+ expect(temp.state).to be_nil
24
+ end
25
+
26
+ it 'returns the default state' do
27
+ temp = Juncture.new 1, 2, 3, default: 1
28
+ expect(temp.state).to eq 1
29
+ end
30
+ end
31
+
32
+ describe '#set' do
33
+ it 'sets the current state' do
34
+ temp = Juncture.new 1, 2, 3
35
+ temp.set 1
36
+ expect(temp.state).to eq 1
37
+ end
38
+
39
+ it 'raises an error if the state is not present' do
40
+ temp = Juncture.new 1, 2, 3
41
+ expect{ temp.set 4 }.to raise_error
42
+ end
43
+ end
44
+
45
+ describe '#==' do
46
+ it 'returns true if matching' do
47
+ temp = Juncture.new 1, 2, 3, default: 2
48
+ expect(temp == 2).to be_true
49
+ end
50
+
51
+ it 'returns false if not matching' do
52
+ temp = Juncture.new 1, 2, 3, default: 2
53
+ expect(temp == 1).to be_false
54
+ end
55
+ end
56
+
57
+ describe '#===' do
58
+ it 'returns true if matching' do
59
+ temp = Juncture.new 1, 2, 3, default: 2
60
+ expect(temp === 2).to be_true
61
+ end
62
+
63
+ it 'returns false if not matching' do
64
+ temp = Juncture.new 1, 2, 3, default: 2
65
+ expect(temp === 1).to be_false
66
+ end
67
+ end
68
+
69
+ describe '#<' do
70
+ it 'returns true if matching' do
71
+ temp = Juncture.new 1, 2, 3, default: 2
72
+ expect(temp < 3).to be_true
73
+ end
74
+
75
+ it 'returns false if not matching' do
76
+ temp = Juncture.new 1, 2, 3, default: 2
77
+ expect(temp < 2).to be_false
78
+ end
79
+ end
80
+
81
+ describe '#<=' do
82
+ it 'returns true if matching' do
83
+ temp = Juncture.new 1, 2, 3, default: 2
84
+ expect(temp <= 2).to be_true
85
+ end
86
+
87
+ it 'returns false if not matching' do
88
+ temp = Juncture.new 1, 2, 3, default: 2
89
+ expect(temp <= 1).to be_false
90
+ end
91
+ end
92
+
93
+ describe '#>' do
94
+ it 'returns true if matching' do
95
+ temp = Juncture.new 1, 2, 3, default: 2
96
+ expect(temp > 1).to be_true
97
+ end
98
+
99
+ it 'returns false if not matching' do
100
+ temp = Juncture.new 1, 2, 3, default: 2
101
+ expect(temp > 2).to be_false
102
+ end
103
+ end
104
+
105
+ describe '#>=' do
106
+ it 'returns true if matching' do
107
+ temp = Juncture.new 1, 2, 3, default: 2
108
+ expect(temp >= 2).to be_true
109
+ end
110
+
111
+ it 'returns false if not matching' do
112
+ temp = Juncture.new 1, 2, 3, default: 2
113
+ expect(temp >= 3).to be_false
114
+ end
115
+ end
116
+
117
+ describe '#method_missing' do
118
+ it 'forards to the state array' do
119
+ temp = Juncture.new 1, 2, 3, default: 2
120
+ expect(temp[1]).to eq 2
121
+ expect(temp.length).to eq 3
122
+ end
123
+
124
+ it 'raises an error to super' do
125
+ temp = Juncture.new 1, 2, 3, default: 2
126
+ expect{ temp.no_response }.to raise_error
127
+ end
128
+ end
129
+ end
@@ -0,0 +1,13 @@
1
+ require 'coveralls'
2
+
3
+ Coveralls.wear!
4
+ require 'juncture'
5
+
6
+ RSpec.configure do |config|
7
+ config.color_enabled = true
8
+ config.formatter = :documentation
9
+ end
10
+
11
+ def fixture_path
12
+ File.expand_path("../fixtures/", __FILE__)
13
+ end
metadata ADDED
@@ -0,0 +1,108 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: juncture
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Ben Slaughter
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-02-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: yard
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: coveralls
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: A State object that can be queried
70
+ email: b.p.slaughter@gmail.com
71
+ executables: []
72
+ extensions: []
73
+ extra_rdoc_files: []
74
+ files:
75
+ - README.md
76
+ - LICENSE
77
+ - lib/juncture/version.rb
78
+ - lib/juncture.rb
79
+ - spec/juncture_spec.rb
80
+ - spec/spec_helper.rb
81
+ homepage: http://benslaughter.github.io/juncture/
82
+ licenses:
83
+ - MIT
84
+ metadata: {}
85
+ post_install_message:
86
+ rdoc_options: []
87
+ require_paths:
88
+ - lib
89
+ required_ruby_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ required_rubygems_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ requirements: []
100
+ rubyforge_project:
101
+ rubygems_version: 2.0.3
102
+ signing_key:
103
+ specification_version: 4
104
+ summary: Simple state object
105
+ test_files:
106
+ - spec/juncture_spec.rb
107
+ - spec/spec_helper.rb
108
+ has_rdoc: