phenomenal 0.9.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.
Files changed (43) hide show
  1. data/LICENSE +27 -0
  2. data/README +3 -0
  3. data/Rakefile +11 -0
  4. data/lib/phenomenal.rb +24 -0
  5. data/lib/phenomenal/adaptation.rb +79 -0
  6. data/lib/phenomenal/conflict_policies.rb +20 -0
  7. data/lib/phenomenal/context.rb +269 -0
  8. data/lib/phenomenal/dsl.rb +119 -0
  9. data/lib/phenomenal/feature.rb +8 -0
  10. data/lib/phenomenal/logger.rb +34 -0
  11. data/lib/phenomenal/manager.rb +317 -0
  12. data/lib/phenomenal/proc.rb +34 -0
  13. data/lib/phenomenal/relationships/context_relationships.rb +22 -0
  14. data/lib/phenomenal/relationships/dsl.rb +18 -0
  15. data/lib/phenomenal/relationships/feature_relationships.rb +42 -0
  16. data/lib/phenomenal/relationships/implication.rb +35 -0
  17. data/lib/phenomenal/relationships/relationship.rb +42 -0
  18. data/lib/phenomenal/relationships/relationships_manager.rb +63 -0
  19. data/lib/phenomenal/relationships/relationships_store.rb +73 -0
  20. data/lib/phenomenal/relationships/requirement.rb +26 -0
  21. data/lib/phenomenal/relationships/suggestion.rb +41 -0
  22. data/lib/phenomenal/version.rb +3 -0
  23. data/spec/adaptation_spec.rb +64 -0
  24. data/spec/behavior/adaptation_spec.rb +5 -0
  25. data/spec/behavior/combined_contexts_spec.rb +5 -0
  26. data/spec/behavior/composition_spec.rb +5 -0
  27. data/spec/behavior/conflict_policy_spec.rb +5 -0
  28. data/spec/behavior/open_context.rb +5 -0
  29. data/spec/behavior/relationships_spec.rb +249 -0
  30. data/spec/context_spec.rb +268 -0
  31. data/spec/dsl_spec.rb +181 -0
  32. data/spec/feature_spec.rb +5 -0
  33. data/spec/manager_spec.rb +84 -0
  34. data/spec/proc_spec.rb +20 -0
  35. data/spec/relationships/context_relationships_spec.rb +13 -0
  36. data/spec/relationships/dsl_spec.rb +13 -0
  37. data/spec/relationships/feature_relationships_spec.rb +13 -0
  38. data/spec/relationships/relationship_spec.rb +31 -0
  39. data/spec/relationships/relationships_manager_spec.rb +15 -0
  40. data/spec/relationships/relationships_store_spec.rb +19 -0
  41. data/spec/spec_helper.rb +18 -0
  42. data/spec/test_classes.rb +111 -0
  43. metadata +124 -0
@@ -0,0 +1,84 @@
1
+ require "spec_helper"
2
+
3
+ describe Phenomenal::Manager do
4
+ before :each do
5
+ @context = Phenomenal::Context.new(:test)
6
+ @context2 = Phenomenal::Context.new(:test2)
7
+ @combined = context :test,:test2
8
+ @manager = Phenomenal::Manager.instance
9
+ end
10
+
11
+ after :each do
12
+ force_forget_context(@context)
13
+ force_forget_context(@context2)
14
+ end
15
+
16
+ describe "#register_context" do
17
+ pending "TODO"
18
+ end
19
+
20
+ describe "#unregister_context" do
21
+ pending "TODO"
22
+ end
23
+
24
+ describe "#register_adaptation" do
25
+ pending "unregister_adaptation"
26
+ end
27
+
28
+ describe "#activate_context" do
29
+ pending "TODO"
30
+ end
31
+
32
+ describe "#deactivate_context" do
33
+ pending "TODO"
34
+ end
35
+
36
+ describe "#proceed" do
37
+ pending "TODO"
38
+ end
39
+
40
+ describe "#change_conflict_policy" do
41
+ pending "TODO"
42
+ end
43
+
44
+ describe "#find_context" do
45
+ it "should return the simple context with the name passed as parameter" do
46
+ @manager.find_context(:test).should==@context
47
+ end
48
+
49
+ it "should raise an error if the context wasn't found" do
50
+ expect {@manager.find_context(:unknown)}.to raise_error Phenomenal::Error
51
+ end
52
+
53
+ it "should return the context immediatly if the argument is a context an is known by the manager" do
54
+ @manager.find_context(@context).should==@context
55
+ end
56
+
57
+ it "should return the combined context matching the list of names passed as parameters" do
58
+ @manager.find_context(:test,:test2).should==@combined
59
+ end
60
+ end
61
+
62
+ describe "#context_defined?" do
63
+ it "should return the context if the context exist" do
64
+ @manager.context_defined?(:test).should==@context
65
+ end
66
+
67
+ it "should return nil if the context doesn't exist" do
68
+ context = Phenomenal::Context.new(:context)
69
+ @manager.context_defined?(:context).should==context
70
+ context.forget
71
+ @manager.context_defined?(:context).should be_nil
72
+ @manager.context_defined?(:unknown).should be_nil
73
+ end
74
+
75
+ it "should work with context references" do
76
+ @manager.context_defined?(@context).should==@context
77
+ end
78
+
79
+ it "should work with combined contexts" do
80
+ @manager.context_defined?(:test,:test2).should==@combined
81
+ @manager.context_defined?(:test,:unknown).should be_nil
82
+ end
83
+ end
84
+ end
data/spec/proc_spec.rb ADDED
@@ -0,0 +1,20 @@
1
+ require "spec_helper"
2
+
3
+ describe Proc do
4
+ describe "#phenomenal_bind" do
5
+ it "should be possible to bind proc as instance methods" do
6
+ p = Proc.new{"Proc"}
7
+ p.should respond_to :phenomenal_bind
8
+ o = BasicObject.new
9
+ p.phenomenal_bind(o).call.should == "Proc"
10
+ end
11
+ end
12
+
13
+ describe "#phenomenal_class_bind" do
14
+ it "should be possible to bind proc as class methods" do
15
+ p = Proc.new{"Proc"}
16
+ p.should respond_to :phenomenal_class_bind
17
+ p.phenomenal_bind(BasicObject).call.should == "Proc"
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,13 @@
1
+ require "spec_helper"
2
+
3
+ describe Phenomenal::ContextRelationships do
4
+ describe "#requires" do
5
+ pending "TODO"
6
+ end
7
+ describe "#implies" do
8
+ pending "TODO"
9
+ end
10
+ describe "#suggests" do
11
+ pending "TODO"
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ require "spec_helper"
2
+
3
+ describe Phenomenal::DSL do
4
+ describe "#requirements_for" do
5
+ pending "TODO"
6
+ end
7
+ describe "#implications_for" do
8
+ pending "TODO"
9
+ end
10
+ describe "#suggestions_for" do
11
+ pending "TODO"
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ require "spec_helper"
2
+
3
+ describe Phenomenal::FeatureRelationships do
4
+ describe "#requirements_for" do
5
+ pending "TODO"
6
+ end
7
+ describe "#implications_for" do
8
+ pending "TODO"
9
+ end
10
+ describe "#suggestions_for" do
11
+ pending "TODO"
12
+ end
13
+ end
@@ -0,0 +1,31 @@
1
+ require "spec_helper"
2
+
3
+ describe Phenomenal::Relationship do
4
+ describe "#==" do
5
+ it "should be true for two relationships with the same source and target" do
6
+ a = Phenomenal::Relationship.new(:source,:target,nil)
7
+ b = Phenomenal::Relationship.new(:source,:target,nil)
8
+ a.should == b
9
+ end
10
+
11
+ it "should be false for relationships concerning different contexts" do
12
+ a = Phenomenal::Relationship.new(:source,:target,nil)
13
+ c = Phenomenal::Relationship.new(:source,:other_target,nil)
14
+ a.should_not == c
15
+ d = Phenomenal::Relationship.new(:other_source,:other_target,nil)
16
+ a.should_not == d
17
+ e = Phenomenal::Relationship.new(:other_source,:target,nil)
18
+ a.should_not == e
19
+ end
20
+
21
+ it "should be false for relationships of different types" do
22
+ a = Phenomenal::Implication.new(:source,:target,nil)
23
+ b = Phenomenal::Requirement.new(:source,:target,nil)
24
+ a.should_not == b
25
+ end
26
+ end
27
+
28
+ describe "#refresh" do
29
+ pending "TODO"
30
+ end
31
+ end
@@ -0,0 +1,15 @@
1
+ require "spec_helper"
2
+
3
+ describe Phenomenal::RelationshipsManager do
4
+ describe "#activate_relationships" do
5
+ pending "TODO"
6
+ end
7
+
8
+ describe "#deactivate_relationships" do
9
+ pending "TODO"
10
+ end
11
+
12
+ describe "#update_relationships_references" do
13
+ pending "TODO"
14
+ end
15
+ end
@@ -0,0 +1,19 @@
1
+ require "spec_helper"
2
+
3
+ describe Phenomenal::RelationshipsStore do
4
+ describe "#add" do
5
+ pending "TODO"
6
+ end
7
+
8
+ describe "#remove" do
9
+ pending "TODO"
10
+ end
11
+
12
+ describe "#update_references" do
13
+ pending "TODO"
14
+ end
15
+
16
+ describe "#get_for" do
17
+ pending "TODO"
18
+ end
19
+ end
@@ -0,0 +1,18 @@
1
+ require 'rspec'
2
+ require "phenomenal"
3
+
4
+ RSpec.configure do |config|
5
+ config.color_enabled = true
6
+ config.formatter = 'progress'
7
+ end
8
+
9
+ def force_forget_context(context)
10
+ while phen_context_active?(context) do
11
+ phen_deactivate_context(context)
12
+ end
13
+ phen_forget_context(context)
14
+ end
15
+
16
+ def define_test_classes
17
+ load "test_classes.rb"
18
+ end
@@ -0,0 +1,111 @@
1
+ # Define the test classes
2
+ class TestString < String
3
+ end
4
+
5
+ class TestClass < String
6
+ @klass_inst_var = 2
7
+ @@klass_var = 1
8
+ attr_accessor :value
9
+ def initialize(str)
10
+ @value=str
11
+ end
12
+ def to_s
13
+ value.to_s
14
+ end
15
+ def eql?(str)
16
+ str.eql?(value.to_s)
17
+ end
18
+
19
+ def self.klass_var_access
20
+ @@klass_var
21
+ end
22
+
23
+ def self.klass_inst_var_access
24
+ @klass_inst_var
25
+ end
26
+
27
+ def print(arg)
28
+ "0 -> ARG: #{arg.to_s}"
29
+ end
30
+ end
31
+
32
+ class Call
33
+ attr_accessor :from
34
+ def initialize(a_string)
35
+ @from=a_string
36
+ end
37
+ def to_s
38
+ "from" + from
39
+ end
40
+ end
41
+
42
+ class Phone
43
+ attr_accessor :incoming_calls, :ongoing_calls, :terminated_calls,
44
+ :missed_calls, :active_call
45
+
46
+ def initialize
47
+ @incoming_calls = Array.new
48
+ @ongoing_calls = Array.new
49
+ @terminated_calls =Array.new
50
+ @missed_calls = Array.new
51
+ @active_call = nil
52
+ end
53
+
54
+ def advertise(a_call)
55
+ "ringtone"
56
+ end
57
+
58
+ def answer
59
+ nextCall = incoming_calls.first
60
+ if nextCall.nil?
61
+ raise ("No incoming calls to answer.")
62
+ end
63
+ answer_call(nextCall)
64
+ end
65
+
66
+ def answer_call(a_call)
67
+ incoming_calls.delete(a_call) do
68
+ raise ("Only incoming calls can be answered.")
69
+ end
70
+ suspend
71
+ ongoingCalls.push(a_call)
72
+ resume(a_call)
73
+ end
74
+
75
+ def hang_up
76
+ if active_call.nil?
77
+ raise ("No active call to hang up")
78
+ end
79
+ hang_up_call(active_call)
80
+ end
81
+
82
+ def hang_up_call(a_call)
83
+ ongoing_calls.delete(a_call) { raise ("Only ongoing calls can be hung up.")}
84
+ if active_call == a_call
85
+ suspend
86
+ end
87
+ terminated_calls.push(a_call)
88
+ end
89
+
90
+ def miss(a_call)
91
+ incoming_calls.delete(a_call) {raise ("Only incoming calls can be missed.")}
92
+ missed_calls.push(a_call)
93
+ end
94
+
95
+ def receive(a_call)
96
+ incoming_calls.push(a_call)
97
+ advertise(a_call)
98
+ end
99
+
100
+ def resume(a_call)
101
+ if !ongoing_calls.include?(a_call)
102
+ raise ("Only ongoing calls can be resumed.")
103
+ end
104
+ active_call(a_call)
105
+ end
106
+
107
+ def suspend
108
+ active_call(nil)
109
+ end
110
+ end
111
+
metadata ADDED
@@ -0,0 +1,124 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: phenomenal
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.9.0
6
+ platform: ruby
7
+ authors:
8
+ - Loic Vigneron - Thibault Poncelet
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-11-24 00:00:00 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rspec
17
+ prerelease: false
18
+ requirement: &id001 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ~>
22
+ - !ruby/object:Gem::Version
23
+ version: "2.5"
24
+ type: :development
25
+ version_requirements: *id001
26
+ description: A context oriented programming framework for Ruby
27
+ email: team@phenomenal-gem.com
28
+ executables: []
29
+
30
+ extensions: []
31
+
32
+ extra_rdoc_files: []
33
+
34
+ files:
35
+ - lib/phenomenal/manager.rb
36
+ - lib/phenomenal/feature.rb
37
+ - lib/phenomenal/proc.rb
38
+ - lib/phenomenal/conflict_policies.rb
39
+ - lib/phenomenal/dsl.rb
40
+ - lib/phenomenal/version.rb
41
+ - lib/phenomenal/relationships/implication.rb
42
+ - lib/phenomenal/relationships/relationships_store.rb
43
+ - lib/phenomenal/relationships/relationship.rb
44
+ - lib/phenomenal/relationships/requirement.rb
45
+ - lib/phenomenal/relationships/dsl.rb
46
+ - lib/phenomenal/relationships/relationships_manager.rb
47
+ - lib/phenomenal/relationships/context_relationships.rb
48
+ - lib/phenomenal/relationships/suggestion.rb
49
+ - lib/phenomenal/relationships/feature_relationships.rb
50
+ - lib/phenomenal/context.rb
51
+ - lib/phenomenal/logger.rb
52
+ - lib/phenomenal/adaptation.rb
53
+ - lib/phenomenal.rb
54
+ - LICENSE
55
+ - Rakefile
56
+ - README
57
+ - spec/spec_helper.rb
58
+ - spec/feature_spec.rb
59
+ - spec/context_spec.rb
60
+ - spec/behavior/composition_spec.rb
61
+ - spec/behavior/combined_contexts_spec.rb
62
+ - spec/behavior/adaptation_spec.rb
63
+ - spec/behavior/open_context.rb
64
+ - spec/behavior/conflict_policy_spec.rb
65
+ - spec/behavior/relationships_spec.rb
66
+ - spec/test_classes.rb
67
+ - spec/manager_spec.rb
68
+ - spec/adaptation_spec.rb
69
+ - spec/relationships/relationships_store_spec.rb
70
+ - spec/relationships/relationship_spec.rb
71
+ - spec/relationships/feature_relationships_spec.rb
72
+ - spec/relationships/dsl_spec.rb
73
+ - spec/relationships/context_relationships_spec.rb
74
+ - spec/relationships/relationships_manager_spec.rb
75
+ - spec/dsl_spec.rb
76
+ - spec/proc_spec.rb
77
+ homepage: http://www.phenomenal-gem.com
78
+ licenses: []
79
+
80
+ post_install_message:
81
+ rdoc_options: []
82
+
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ none: false
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: 1.9.2
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ none: false
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: "0"
97
+ requirements: []
98
+
99
+ rubyforge_project:
100
+ rubygems_version: 1.8.11
101
+ signing_key:
102
+ specification_version: 3
103
+ summary: A context oriented programming framework for Ruby
104
+ test_files:
105
+ - spec/spec_helper.rb
106
+ - spec/feature_spec.rb
107
+ - spec/context_spec.rb
108
+ - spec/behavior/composition_spec.rb
109
+ - spec/behavior/combined_contexts_spec.rb
110
+ - spec/behavior/adaptation_spec.rb
111
+ - spec/behavior/open_context.rb
112
+ - spec/behavior/conflict_policy_spec.rb
113
+ - spec/behavior/relationships_spec.rb
114
+ - spec/test_classes.rb
115
+ - spec/manager_spec.rb
116
+ - spec/adaptation_spec.rb
117
+ - spec/relationships/relationships_store_spec.rb
118
+ - spec/relationships/relationship_spec.rb
119
+ - spec/relationships/feature_relationships_spec.rb
120
+ - spec/relationships/dsl_spec.rb
121
+ - spec/relationships/context_relationships_spec.rb
122
+ - spec/relationships/relationships_manager_spec.rb
123
+ - spec/dsl_spec.rb
124
+ - spec/proc_spec.rb