answer-factory 0.0.12 → 0.0.13

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.12
1
+ 0.0.13
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{answer-factory}
8
- s.version = "0.0.12"
8
+ s.version = "0.0.13"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Bill Tozier", "Trek Glowacki", "Jesse Sielaff"]
12
- s.date = %q{2010-05-06}
12
+ s.date = %q{2010-05-07}
13
13
  s.default_executable = %q{answer-factory}
14
14
  s.description = %q{The pragmaticgp gem provides a simple framework for building, running and managing genetic programming experiments which automatically discover algorithms and equations to solve user-defined problems.}
15
15
  s.email = %q{bill@vagueinnovation.com}
@@ -26,7 +26,6 @@ Gem::Specification.new do |s|
26
26
  "_spikes/old_vs_new_dominated_by?.rb",
27
27
  "answer-factory.gemspec",
28
28
  "bin/answer-factory",
29
- "config/database.yml",
30
29
  "lib/answer-factory.rb",
31
30
  "lib/answers/answer.rb",
32
31
  "lib/answers/batch.rb",
@@ -50,9 +49,10 @@ Gem::Specification.new do |s|
50
49
  "readme.md",
51
50
  "spec/answer_spec.rb",
52
51
  "spec/batch_spec.rb",
53
- "spec/config_spec.rb",
54
52
  "spec/factories/factory_spec.rb",
55
53
  "spec/factories/workstation_spec.rb",
54
+ "spec/integration_specs/activate_integration.rb",
55
+ "spec/integration_specs/build_integration.rb",
56
56
  "spec/integration_specs/thor_integration.rb",
57
57
  "spec/operators/any_one_sampler_spec.rb",
58
58
  "spec/operators/dominated_quantile_spec.rb",
@@ -83,9 +83,10 @@ Gem::Specification.new do |s|
83
83
  s.test_files = [
84
84
  "spec/answer_spec.rb",
85
85
  "spec/batch_spec.rb",
86
- "spec/config_spec.rb",
87
86
  "spec/factories/factory_spec.rb",
88
87
  "spec/factories/workstation_spec.rb",
88
+ "spec/integration_specs/activate_integration.rb",
89
+ "spec/integration_specs/build_integration.rb",
89
90
  "spec/integration_specs/thor_integration.rb",
90
91
  "spec/operators/any_one_sampler_spec.rb",
91
92
  "spec/operators/dominated_quantile_spec.rb",
@@ -2,6 +2,7 @@ $: << File.join(File.dirname(__FILE__), "/../lib")
2
2
 
3
3
  require 'rubygems'
4
4
  require 'nudge'
5
+ require 'configatron'
5
6
 
6
7
  require 'couchrest'
7
8
 
@@ -1,53 +1,61 @@
1
1
  module AnswerFactory
2
2
  class Factory
3
3
  require 'open-uri'
4
- require 'configatron'
5
4
 
6
5
  attr_reader :name
7
- attr_reader :instruction_library, :type_library
6
+ attr_reader :nudge_instructions
7
+ attr_reader :nudge_types
8
+ attr_reader :couchdb_server
8
9
  attr_accessor :workstation_names
9
10
  attr_reader :original_options_hash
10
11
 
11
12
 
12
- def initialize(name = "my_factory", options = {})
13
- @name = name
14
- @original_options_hash = options
15
- @instruction_library = options[:instruction_library] || Instruction.all_instructions
16
- @type_library = options[:type_library] || NudgeType.all_types
17
- @workstation_names = Array.new
13
+ def initialize(options = {})
18
14
 
19
- self.configure!
15
+ # Factory instance settings
16
+ @name = options[:name] ||
17
+ configatron.factory.retrieve(:name,nil) ||
18
+ "my_factory"
19
+
20
+ @workstation_names = options[:workstation_names] ||
21
+ configatron.factory.retrieve(:workstation_names, nil) ||
22
+ Array.new
23
+
24
+ # CouchDB settings
25
+ @couchdb_server = options[:couchdb_server] ||
26
+ configatron.factory.couchdb.retrieve(:server, nil) ||
27
+ "http://127.0.0.1:5984"
28
+
29
+ # Nudge language settings
30
+ @nudge_instructions = options[:nudge_instructions] ||
31
+ configatron.nudge.instructions.retrieve(:all, nil) ||
32
+ Instruction.all_instructions
33
+
34
+ @nudge_types = options[:nudge_types] ||
35
+ configatron.nudge.types.retrieve(:all, nil) ||
36
+ NudgeType.all_types
37
+
38
+ update_configatron!
39
+ end
40
+
41
+
42
+ # this apparent redundancy saves project-based
43
+ # and command-line overrides
44
+ def update_configatron!
45
+ configatron.factory.name = @name
46
+ configatron.nudge.instructions.all = @nudge_instructions
47
+ configatron.nudge.types.all = @nudge_types
48
+ configatron.factory.workstation_names = @workstation_names
49
+ configatron.factory.couchdb.server = @couchdb_server
20
50
  end
21
51
 
22
52
 
23
53
  def couch_available?
24
- open(self.configatron.couchdb_uri).status
54
+ open(configatron.factory.couchdb.server).status
25
55
  true
26
56
  rescue StandardError
27
57
  false
28
58
  end
29
59
 
30
-
31
- def configure!
32
- self.configure_constants!
33
- self.configure_paths!
34
- self.configure_databases!
35
- end
36
-
37
-
38
- def configure_constants!
39
- self.configatron.factory_name = self.name
40
- end
41
-
42
-
43
- def configure_paths!
44
- self.configatron.factory_root = File.expand_path("#{File.dirname(__FILE__)}/../..")
45
- end
46
-
47
-
48
- def configure_databases!
49
- self.configatron.configure_from_yaml("#{self.configatron.factory_root}/config/database.yml")
50
- self.configatron.couchdb_uri = "#{self.configatron.main_database.db_root}/#{self.name}"
51
- end
52
60
  end
53
61
  end
@@ -2,102 +2,178 @@ require File.join(File.dirname(__FILE__), "./../spec_helper")
2
2
 
3
3
 
4
4
  describe "Factory" do
5
-
6
- it "should have a name" do
7
- Factory.new("foo_factory").name.should == "foo_factory"
8
- end
9
-
10
- it "should have a default name of 'something here'" do
11
- Factory.new.name.should == "my_factory"
12
- end
13
-
14
-
15
- describe "databases" do
16
- describe "#couch_available?" do
17
- it "should have a method to check that couchDB is accessible" do
18
- f1 = Factory.new("boo")
19
- lambda{f1.couch_available?}.should_not raise_error
5
+ describe "Factory configuration methods" do
6
+ describe "defaults, via configatron" do
7
+ it "should be possible to talk to to #configatron from here" do
8
+ lambda{configatron.my_thing}.should_not raise_error
20
9
  end
21
10
 
22
- it "should return true if the uri is reachable" do
23
- uri = "http://mycouch.db/boo"
24
- f1 = Factory.new("boo")
25
- f1.configatron.couchdb_uri = uri
26
- FakeWeb.register_uri(:any, uri, :body => "We are here!", :status => [200, "OK"])
27
- f1.couch_available?.should == true
11
+ describe "Factory.new should have reasonable default values" do
12
+ it "should use 'my_factory' for #name" do
13
+ f1 = Factory.new
14
+ f1.name.should == "my_factory"
15
+ end
16
+
17
+ it "should use an empty Array for #workstation_names" do
18
+ f1 = Factory.new
19
+ f1.workstation_names.should == []
20
+ end
21
+
22
+ it "should use 'http://127.0.0.1:5984' for #couchdb_server" do
23
+ f1 = Factory.new
24
+ f1.couchdb_server.should == 'http://127.0.0.1:5984'
25
+ end
26
+
27
+ it "should use Nudge::Instruction.all_instructions for #nudge_instructions" do
28
+ f1 = Factory.new
29
+ f1.nudge_instructions.should == Instruction.all_instructions
30
+ end
31
+
32
+ it "should use Nudge::NudgeType.all_types for #nudge_types" do
33
+ f1 = Factory.new
34
+ f1.nudge_types.should == NudgeType.all_types
35
+ end
28
36
  end
29
37
 
30
- it "should return false if the uri is offline or 404's out" do
31
- uri = "http://mycouch.db/boo"
32
- f1 = Factory.new("boo")
33
- f1.configatron.couchdb_uri = uri
34
- f1.configatron.couchdb_uri.should == uri
35
- FakeWeb.register_uri(:any, uri, :body => "Go away!", :status => [404, "Not Found"])
36
- f1.couch_available?.should == false
38
+
39
+ describe "Factory.new should hit configatron for default values" do
40
+ it "should hit configatron for #name" do
41
+ configatron.temp do
42
+ configatron.factory.name = "foo"
43
+ f1 = Factory.new
44
+ f1.name.should == "foo"
45
+ end
46
+ end
47
+
48
+ it "should hit configatron for #nudge_instructions" do
49
+ configatron.temp do
50
+ configatron.nudge.instructions.all = [IntSubtractInstruction]
51
+ f1 = Factory.new
52
+ f1.nudge_instructions.should == [IntSubtractInstruction]
53
+ end
54
+ end
55
+
56
+ it "should hit configatron for #nudge_types" do
57
+ configatron.temp do
58
+ configatron.nudge.types.all = [BoolType]
59
+ f1 = Factory.new
60
+ f1.nudge_types.should == [BoolType]
61
+ end
62
+ end
37
63
 
38
- f1 = Factory.new("boo") # depends on this being wrong
39
- f1.configatron.couchdb_uri = "http://127.0.0.1:9991/place"
40
- f1.couch_available?.should == false
64
+ it "should hit configatron for #workstation_names" do
65
+ configatron.temp do
66
+ configatron.factory.workstation_names = [:bar, :baz]
67
+ f1 = Factory.new
68
+ f1.workstation_names.should == [:bar, :baz]
69
+ end
70
+ end
71
+
72
+ it "should hit configatron for #couchdb_server" do
73
+ configatron.temp do
74
+ configatron.factory.couchdb.server = "http://my.otherplace.com:7771"
75
+ f1 = Factory.new
76
+ f1.couchdb_server.should == "http://my.otherplace.com:7771"
77
+ end
78
+ end
79
+
80
+ end
81
+
82
+
83
+ describe "writing overridden defaults to configatron" do
84
+ describe "Factory.new should overwrite configatron default values" do
85
+ it "should overwrite #factory_name" do
86
+ Factory.new(name:"golly")
87
+ configatron.factory.name.should == "golly"
88
+ end
89
+
90
+ it "should overwrite #nudge.instructions.all" do
91
+ Factory.new(nudge_instructions:[BoolAndInstruction])
92
+ configatron.nudge.instructions.all.should == [BoolAndInstruction]
93
+ end
94
+
95
+ it "should overwrite #nudge.types.all" do
96
+ Factory.new(nudge_types:[BoolType])
97
+ configatron.nudge.types.all.should == [BoolType]
98
+ end
99
+
100
+ it "should overwrite #factory.workstation_names" do
101
+ Factory.new(workstation_names:[:xenon])
102
+ configatron.factory.workstation_names.should == [:xenon]
103
+ end
104
+
105
+ it "should overwrite #factory.couchdb.server" do
106
+ Factory.new(couchdb_server:"http://127.0.0.1:9999")
107
+ configatron.factory.couchdb.server.should == "http://127.0.0.1:9999"
108
+ end
109
+ end
41
110
  end
111
+
42
112
  end
43
- end
44
-
45
-
46
- describe "build" do
47
- it "should read the config files"
48
-
49
- it "should #reset"
50
- end
51
-
52
-
53
- describe "reset" do
54
- it "should erase the couchdb"
55
113
 
56
- it "should set up a new couchdb"
57
114
 
58
- it "should set up the necessary design documents in the db"
59
- end
60
-
61
-
62
- describe "activate" do
63
- it "should check the config files"
64
- end
65
-
66
-
67
- describe "ontology" do
68
- it "should have a master Instruction list" do
69
- Factory.new("foo").instruction_library.should == Instruction.all_instructions
70
- end
71
-
72
- it "should be possible to override the default with an option" do
73
- short_list = [IntAddInstruction, CodeNoopInstruction]
74
- Factory.new("foo", instruction_library:short_list).instruction_library.should ==
75
- short_list
115
+ describe "databases" do
116
+ describe "#couch_available?" do
117
+ before(:each) do
118
+ FakeWeb.allow_net_connect = false
119
+ end
120
+
121
+ it "should have a method to check that couchDB is accessible" do
122
+ f1 = Factory.new(name:"boo")
123
+ lambda{f1.couch_available?}.should_not raise_error
124
+ end
125
+
126
+ it "should return true if the uri is reachable" do
127
+ uri = "http://mycouch.db/boo"
128
+ f1 = Factory.new(name:"boo", couchdb_server:uri)
129
+ FakeWeb.register_uri(:any, uri, :body => "We are here!", :status => [200, "OK"])
130
+ f1.couch_available?.should == true
131
+ end
132
+
133
+ it "should return false if the uri is offline or 404's out" do
134
+ uri = "http://mycouch.db/boo"
135
+ f1 = Factory.new(name:"boo", couchdb_server:uri)
136
+ FakeWeb.register_uri(:any, "http://mycouch.db/boo",
137
+ :body => "Go away!", :status => [404, "Not Found"])
138
+ f1.couch_available?.should == false
139
+
140
+ f1 = Factory.new(name:"boo", couchdb_server:"http://127.0.0.1:9991/place")
141
+ f1.couch_available?.should == false
142
+ end
143
+ end
144
+
145
+
146
+ describe "database setup" do
147
+ describe "paths" do
148
+ it "should have reasonable defaults"
149
+
150
+ describe "setting from file" do
151
+ it "should populate configatron.main_database.db_root"
152
+
153
+ it "should populate configatron.main_database.db_name"
154
+ end
155
+ end
156
+ end
76
157
  end
77
158
 
78
- it "should have a master NudgeType list" do
79
- Factory.new("foo").type_library.should == NudgeType.all_types
80
- end
81
159
 
82
- it "should be possible to override the default with an option" do
83
- short_list = [CodeType, BoolType]
84
- Factory.new("foo", type_library:short_list).type_library.should ==
85
- short_list
160
+ describe "Nudge Language setup" do
161
+ it "should have reasonable defaults"
162
+
163
+ describe "setting from file" do
164
+ it "should replace configatron.ontology.nudge.types"
165
+ it "should replace configatron.ontology.nudge.instructions"
166
+ end
86
167
  end
87
168
 
88
- it "should save all the Hash options it was called with" do
89
- Factory.new("bar", my_option:1, my_other_option:[1,2,3]).original_options_hash.should ==
90
- {:my_option=>1, :my_other_option=>[1, 2, 3]}
91
- end
92
169
 
93
- end
94
-
95
- describe "workstations" do
96
- it "should have a list of extant workstation names" do
97
- Factory.new.workstation_names.should == []
170
+ describe "Workstation setup" do
171
+ it "should have reasonable defaults"
172
+
173
+ describe "setting from file" do
174
+ it "should replace configatron.workstations"
175
+ it "should replace 'configatron.[workstation_name].[settings]' for each workstation"
176
+ end
98
177
  end
99
-
100
178
  end
101
-
102
-
103
179
  end
@@ -93,6 +93,11 @@ describe "Workstation" do
93
93
 
94
94
 
95
95
  describe "#cycle" do
96
+
97
+ describe "the #before_cycle method" do
98
+ it "should empty @answers"
99
+ end
100
+
96
101
  it "should invoke #receive!, #build!, #ship! and #scrap!" do
97
102
  w1 = Workstation.new(:place)
98
103
  w1.should_receive(:receive!)
@@ -102,11 +107,7 @@ describe "Workstation" do
102
107
  w1.cycle
103
108
  end
104
109
 
105
- describe "the #before method" do
106
- it "should empty @answers"
107
- end
108
-
109
- describe "the #after method" do
110
+ describe "the #after_cycle method" do
110
111
  it "should save everything in @answers to the persistent store"
111
112
  end
112
113
 
File without changes
File without changes
@@ -2,26 +2,20 @@ require 'answer-factory'
2
2
 
3
3
  ####
4
4
  ####
5
- #### EDIT THESE SETTINGS TO SUIT YOUR PROJECT'S NEEDS
5
+ #### EDIT THESE SETTINGS TO SUIT YOUR PROJECT:
6
6
  ####
7
7
  ####
8
8
 
9
- def AnswerFactory.nudge_instructions_path
10
- # Directory path for project-specific Nudge instructions:
11
- '/lib/nudge/instructions/*'
12
- end
13
-
14
- def AnswerFactory.nudge_types_path
15
- # Directory path for project-specific Nudge types:
16
- '/lib/nudge/types/*'
17
- end
9
+ # Nudge language extensions:
10
+ configatron.project.nudge.instructions.path = '/lib/nudge/instructions/*'
11
+ configatron.project.nudge.types.path = '/lib/nudge/types/*'
18
12
 
19
13
 
20
14
  ####
21
15
  ####
22
- #### DO NOT EDIT THE FOLLOWING CODE
16
+ #### DON'T EDIT PAST THIS POINT
23
17
  ####
24
18
  ####
25
19
 
26
- Dir.glob(File.dirname(__FILE__) + AnswerFactory.nudge_instructions_path) {|file| require file}
27
- Dir.glob(File.dirname(__FILE__) + AnswerFactory.nudge_types_path) {|file| require file}
20
+ Dir.glob(File.dirname(__FILE__) + configatron.project.nudge.instructions.path) {|file| require file}
21
+ Dir.glob(File.dirname(__FILE__) + configatron.project.nudge.types.path) {|file| require file}
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 12
9
- version: 0.0.12
8
+ - 13
9
+ version: 0.0.13
10
10
  platform: ruby
11
11
  authors:
12
12
  - Bill Tozier
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2010-05-06 00:00:00 -04:00
19
+ date: 2010-05-07 00:00:00 -04:00
20
20
  default_executable: answer-factory
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
@@ -130,7 +130,6 @@ files:
130
130
  - _spikes/old_vs_new_dominated_by?.rb
131
131
  - answer-factory.gemspec
132
132
  - bin/answer-factory
133
- - config/database.yml
134
133
  - lib/answer-factory.rb
135
134
  - lib/answers/answer.rb
136
135
  - lib/answers/batch.rb
@@ -154,9 +153,10 @@ files:
154
153
  - readme.md
155
154
  - spec/answer_spec.rb
156
155
  - spec/batch_spec.rb
157
- - spec/config_spec.rb
158
156
  - spec/factories/factory_spec.rb
159
157
  - spec/factories/workstation_spec.rb
158
+ - spec/integration_specs/activate_integration.rb
159
+ - spec/integration_specs/build_integration.rb
160
160
  - spec/integration_specs/thor_integration.rb
161
161
  - spec/operators/any_one_sampler_spec.rb
162
162
  - spec/operators/dominated_quantile_spec.rb
@@ -212,9 +212,10 @@ summary: Genetic Programming in the Nudge language
212
212
  test_files:
213
213
  - spec/answer_spec.rb
214
214
  - spec/batch_spec.rb
215
- - spec/config_spec.rb
216
215
  - spec/factories/factory_spec.rb
217
216
  - spec/factories/workstation_spec.rb
217
+ - spec/integration_specs/activate_integration.rb
218
+ - spec/integration_specs/build_integration.rb
218
219
  - spec/integration_specs/thor_integration.rb
219
220
  - spec/operators/any_one_sampler_spec.rb
220
221
  - spec/operators/dominated_quantile_spec.rb
data/config/database.yml DELETED
@@ -1,9 +0,0 @@
1
- # realy wants to use CouchDB version 0.11 or higher
2
-
3
- # edit this to fit your particular CouchDB configuration
4
- main_database:
5
- db_root: http://127.0.0.1:5984 # URI of your CouchDB server
6
- db_name: my_factory # root database handling your AnswerFactory:
7
- tag_filter: _design/routing/_view/by_tag # don't edit this unless you also
8
- # change how it's used in the codebase!
9
-
data/spec/config_spec.rb DELETED
@@ -1,94 +0,0 @@
1
- require File.join(File.dirname(__FILE__), "./spec_helper")
2
-
3
-
4
- describe "Factory configuration methods" do
5
- describe "configatron integration" do
6
- it "should respond to #configatron" do
7
- Factory.new.should respond_to(:configatron)
8
- end
9
- end
10
-
11
-
12
- describe "configure_paths" do
13
- it "should respond to #configure_paths" do
14
- Factory.new.should respond_to(:configure_paths!)
15
- end
16
-
17
- it "should populate self.configatron.factory_root as the path to the project folder" do
18
- this_spec_file_parent_path = File.expand_path("#{File.dirname(__FILE__)}/..")
19
- f1 = Factory.new
20
- f1.configure_paths!
21
- f1.configatron.factory_root.should == this_spec_file_parent_path
22
- end
23
- end
24
-
25
-
26
- describe "factory name" do
27
- it "should populate self.configatron.factory_name" do
28
- f1 = Factory.new
29
- f1.configure_constants!
30
- f1.configatron.factory_name.should == "my_factory"
31
-
32
- f1 = Factory.new("super_fancy")
33
- f1.configure_constants!
34
- f1.configatron.factory_name.should == "super_fancy"
35
- end
36
- end
37
-
38
-
39
- describe "database setup" do
40
- describe "paths" do
41
- it "should read from database.yml" do
42
- f1 = Factory.new("super_fancy")
43
- f1.configatron.should_receive(:configure_from_yaml)
44
- f1.configure!
45
- end
46
-
47
- describe "subject" do
48
- before(:each) do
49
- @f1 = Factory.new()
50
- @f1.configure!
51
- end
52
-
53
- it "should populate configatron.main_database.db_root" do
54
- @f1.configatron.main_database.db_root.should == "http://127.0.0.1:5984"
55
- end
56
-
57
- it "should populate configatron.main_database.db_name" do
58
- @f1.configatron.main_database.db_name.should == "my_factory" # from the config file
59
- end
60
-
61
- it "should populate configatron.main_database.tag_filter" do
62
- @f1.configatron.main_database.tag_filter.should == "_design/routing/_view/by_tag"
63
- end
64
- end
65
-
66
- end
67
-
68
- describe "checking for CouchDB access" do
69
- it "should call Factory#couch_db?"
70
- end
71
-
72
- describe "setting up initial db" do
73
- it "should not remove old records unless asked to do so"
74
- it "should be possible to erase the db if a flag is set"
75
- it "should set up the design document"
76
- it "should write the search-by-tag filter view to the design document"
77
- end
78
- end
79
-
80
-
81
- describe "Nudge language setup" do
82
- it "should set up the Instructions"
83
-
84
- it "should set up the Types"
85
-
86
- end
87
-
88
- end
89
-
90
-
91
-
92
-
93
-
94
-