picky-generators 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. data/bin/picky-generate +14 -0
  2. data/lib/picky-generators.rb +7 -0
  3. data/lib/picky-generators/generators/base.rb +120 -0
  4. data/lib/picky-generators/generators/client/sinatra.rb +39 -0
  5. data/lib/picky-generators/generators/not_found_exception.rb +35 -0
  6. data/lib/picky-generators/generators/selector.rb +46 -0
  7. data/lib/picky-generators/generators/server/unicorn.rb +41 -0
  8. data/prototypes/client/sinatra/Gemfile +13 -0
  9. data/prototypes/client/sinatra/app.rb +65 -0
  10. data/prototypes/client/sinatra/book.rb +42 -0
  11. data/prototypes/client/sinatra/config.ru +2 -0
  12. data/prototypes/client/sinatra/images/picky.png +0 -0
  13. data/prototypes/client/sinatra/javascripts/jquery-1.3.2.js +4376 -0
  14. data/prototypes/client/sinatra/javascripts/jquery-1.4.3.min.js +166 -0
  15. data/prototypes/client/sinatra/javascripts/jquery.scrollTo-1.4.2.js +215 -0
  16. data/prototypes/client/sinatra/javascripts/jquery.timer.js +75 -0
  17. data/prototypes/client/sinatra/javascripts/picky.min.js +17 -0
  18. data/prototypes/client/sinatra/library.csv +540 -0
  19. data/prototypes/client/sinatra/stylesheets/stylesheet.css +184 -0
  20. data/prototypes/client/sinatra/stylesheets/stylesheet.sass +225 -0
  21. data/prototypes/client/sinatra/views/configure.haml +170 -0
  22. data/prototypes/client/sinatra/views/search.haml +96 -0
  23. data/prototypes/server/unicorn/Gemfile +30 -0
  24. data/prototypes/server/unicorn/Rakefile +11 -0
  25. data/prototypes/server/unicorn/app/README +5 -0
  26. data/prototypes/server/unicorn/app/application.rb +50 -0
  27. data/prototypes/server/unicorn/app/db.yml +13 -0
  28. data/prototypes/server/unicorn/app/library.csv +540 -0
  29. data/prototypes/server/unicorn/app/logging.rb +20 -0
  30. data/prototypes/server/unicorn/config.ru +35 -0
  31. data/prototypes/server/unicorn/log/README +1 -0
  32. data/prototypes/server/unicorn/script/console +34 -0
  33. data/prototypes/server/unicorn/tmp/README +0 -0
  34. data/prototypes/server/unicorn/tmp/pids/README +0 -0
  35. data/prototypes/server/unicorn/unicorn.ru +15 -0
  36. data/spec/lib/picky-generators/generators/base_spec.rb +83 -0
  37. data/spec/lib/picky-generators/generators/client/sinatra_spec.rb +35 -0
  38. data/spec/lib/picky-generators/generators/selector_spec.rb +42 -0
  39. data/spec/lib/picky-generators/generators/server/unicorn_spec.rb +35 -0
  40. metadata +147 -0
@@ -0,0 +1,20 @@
1
+ # Standard logging.
2
+ #
3
+ require 'logger'
4
+ PickyLog = Loggers::Search.new ::Logger.new(File.expand_path('log/search.log', PICKY_ROOT))
5
+
6
+ # Example with using the syslog logger.
7
+ # Falling back to the standard log if it isn't available.
8
+ # (For example, because it is used locally and syslog is
9
+ # only available on the servers)
10
+ #
11
+ # begin
12
+ # log_program_name = 'search/query'
13
+ # logger = SyslogLogger.new log_program_name
14
+ # PickyLog = Loggers::Search.new logger
15
+ # puts "Logging on syslog #{log_program_name}."
16
+ # rescue StandardError
17
+ # puts "Could not connect to the syslog, using the normal log."
18
+ # require 'logger'
19
+ # PickyLog = Loggers::Search.new ::Logger.new(File.join(PICKY_ROOT, 'log/search.log'))
20
+ # end
@@ -0,0 +1,35 @@
1
+ # Require the gem. This loads the search framework.
2
+ #
3
+ require 'picky'
4
+
5
+ # Load your application. This requires the following files in
6
+ #
7
+ # * lib/initializers/*.rb
8
+ # * lib/tokenizers/*.rb
9
+ # * lib/indexers/*.rb
10
+ # * lib/query/*.rb
11
+ #
12
+ # * app/logging.rb
13
+ # * app/application.rb
14
+ #
15
+ # (in that order).
16
+ #
17
+ Loader.load_application
18
+
19
+ # Load the indexes into the memory.
20
+ #
21
+ Indexes.load_from_cache
22
+
23
+ # Use Harakiri middleware to kill worker child after X requests.
24
+ #
25
+ # Works only with web servers that fork worker children and which
26
+ # fork new children, like for example Unicorn.
27
+ #
28
+ Rack::Harakiri.after = 50
29
+ use Rack::Harakiri
30
+
31
+ # Start accepting requests.
32
+ #
33
+ # Note: Needs to be the same constant name as in app/application.rb.
34
+ #
35
+ run PickySearch
@@ -0,0 +1 @@
1
+ Logs go here by default.
@@ -0,0 +1,34 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+ #
4
+ irb = 'irb'
5
+
6
+ require 'optparse'
7
+ options = { :sandbox => false, :irb => irb }
8
+ OptionParser.new do |opt|
9
+ opt.banner = "Usage: console [environment] [options]"
10
+ opt.on("--irb=[#{irb}]", 'Invoke a different irb.') { |v| options[:irb] = v }
11
+ opt.parse!(ARGV)
12
+ end
13
+
14
+ libs = " -r irb/completion"
15
+ libs << %( -r "picky" )
16
+
17
+ mapping = {
18
+ 'p' => 'production',
19
+ 'd' => 'development',
20
+ 't' => 'test'
21
+ }
22
+ given_env = ARGV.first
23
+ ENV['PICKY_ENV'] = mapping[given_env] || given_env || ENV['PICKY_ENV'] || 'development'
24
+
25
+ puts "Use \x1b[1;30mLoader.load_application\x1b[m to load app."
26
+ puts "Use \x1b[1;30mIndexes.load_from_cache\x1b[m after that to load indexes."
27
+ puts "Copy the following line to do just that:"
28
+ puts "\x1b[1;30mLoader.load_application; Indexes.load_from_cache; nil\x1b[m"
29
+ puts ""
30
+ puts "Now you can for example create a query instance."
31
+ puts "\x1b[1;30mfull_books = Query::Full.new(Indexes[:books]); nil\x1b[m"
32
+ puts "and search on it"
33
+ puts "\x1b[1;30mfull_books.search_with_text 'bla'\x1b[m"
34
+ exec "#{options[:irb]} #{libs} --simple-prompt"
File without changes
@@ -0,0 +1,15 @@
1
+ listen '0.0.0.0:8080'
2
+ pid 'tmp/pids/unicorn.pid'
3
+ preload_app true
4
+ stderr_path 'log/unicorn.stderr.log'
5
+ stdout_path 'log/unicorn.stdout.log'
6
+ timeout 10
7
+ worker_processes 2
8
+
9
+ # After forking, the GC is disabled, because we
10
+ # kill off the workers after x requests and fork
11
+ # new ones – so the GC doesn't run.
12
+ #
13
+ after_fork do |_, _|
14
+ GC.disable
15
+ end
@@ -0,0 +1,83 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe Picky::Generators do
5
+
6
+ describe Picky::Generators::Base do
7
+
8
+ before(:each) do
9
+ @generators = Picky::Generators::Base.new :identifier, 'some_name', 'some/path'
10
+ @generators.stub! :exclaim
11
+ end
12
+
13
+ context "after initialize" do
14
+ it 'has the right identifier' do
15
+ @generators.identifier.should == :identifier
16
+ end
17
+ it 'has the right name' do
18
+ @generators.name.should == 'some_name'
19
+ end
20
+ it 'has the right prototype dir' do
21
+ @generators.prototype_basedir.should == File.expand_path('../../../../../prototypes/some/path', __FILE__)
22
+ end
23
+ end
24
+
25
+ describe "create_target_directory" do
26
+ context "file exists" do
27
+ before(:each) do
28
+ File.stub! :exists? => true
29
+ end
30
+ it "should just tell the user that" do
31
+ @generators.stub! :target_directory => :some_target_directory
32
+
33
+ @generators.should_receive(:exists).once.with :some_target_directory
34
+
35
+ @generators.create_target_directory
36
+ end
37
+ it "should not make the directory" do
38
+ FileUtils.should_receive(:mkdir).never
39
+
40
+ @generators.create_target_directory
41
+ end
42
+ end
43
+ context "file does not exist" do
44
+ before(:each) do
45
+ File.stub! :exists? => false
46
+ FileUtils.stub! :mkdir
47
+ end
48
+ it "should make the directory" do
49
+ @generators.stub! :target_directory => :some_target_directory
50
+
51
+ FileUtils.should_receive(:mkdir).once.with :some_target_directory
52
+
53
+ @generators.create_target_directory
54
+ end
55
+ it "should tell the user" do
56
+ @generators.stub! :target_directory => :some_target_directory
57
+
58
+ @generators.should_receive(:created).once.with :some_target_directory
59
+
60
+ @generators.create_target_directory
61
+ end
62
+ end
63
+ end
64
+
65
+ describe "target_filename_for" do
66
+ it "should return the right filename" do
67
+ @generators.stub! :target_directory => 'some_target_directory'
68
+
69
+ test_filename = File.expand_path 'some/file/name', @generators.prototype_basedir
70
+
71
+ @generators.target_filename_for(test_filename).should == 'some_target_directory/some/file/name'
72
+ end
73
+ end
74
+
75
+ describe "target_directory" do
76
+ it "should return the right dir name" do
77
+ @generators.target_directory.should == File.expand_path('../../../../../some_name', __FILE__)
78
+ end
79
+ end
80
+
81
+ end
82
+
83
+ end
@@ -0,0 +1,35 @@
1
+ # encoding: utf-8
2
+ #
3
+ require 'spec_helper'
4
+
5
+ describe Picky::Generators::Client::Sinatra do
6
+
7
+ before(:each) do
8
+ @sinatra = Picky::Generators::Client::Sinatra.new :sinatra_client, 'sinatra_client_dir_name'
9
+ @sinatra.stub! :exclaim
10
+ end
11
+
12
+ context "after initialize" do
13
+ it 'has the right identifier' do
14
+ @sinatra.identifier.should == :sinatra_client
15
+ end
16
+ it 'has the right name' do
17
+ @sinatra.name.should == 'sinatra_client_dir_name'
18
+ end
19
+ it 'has the right prototype dir' do
20
+ @sinatra.prototype_basedir.should == File.expand_path('../../../../../../prototypes/client/sinatra', __FILE__)
21
+ end
22
+ end
23
+
24
+ describe "generate" do
25
+ it "should do things in order" do
26
+ @sinatra.should_receive(:exclaim).once.ordered # Initial explanation
27
+ @sinatra.should_receive(:create_target_directory).once.ordered
28
+ @sinatra.should_receive(:copy_all_files).once.ordered
29
+ @sinatra.should_receive(:exclaim).at_least(7).times.ordered # Some user steps to do
30
+
31
+ @sinatra.generate
32
+ end
33
+ end
34
+
35
+ end
@@ -0,0 +1,42 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe Picky::Generators::Selector do
5
+
6
+ describe "main class" do
7
+ before(:each) do
8
+ @selector = Picky::Generators::Selector.new
9
+ end
10
+
11
+ describe "generator_for_class" do
12
+ it "should return me a generator for the given class" do
13
+ @selector.generator_for_class(Picky::Generators::Server::Unicorn, :identifier, :some_args).should be_kind_of(Picky::Generators::Server::Unicorn)
14
+ end
15
+ end
16
+
17
+ describe "generator_for" do
18
+ it "should not raise if a generator is available" do
19
+ lambda { @selector.generator_for('sinatra_client', 'some_project') }.should_not raise_error
20
+ end
21
+ it "should not raise if a generator is available" do
22
+ lambda { @selector.generator_for('unicorn_server', 'some_project') }.should_not raise_error
23
+ end
24
+
25
+ it "should raise if a generator is not available" do
26
+ lambda { @selector.generator_for('blarf', 'gnorf') }.should raise_error(Picky::Generators::NotFoundException)
27
+ end
28
+ end
29
+
30
+ describe "generate" do
31
+ it "should raise a NoGeneratorException if called with the wrong params" do
32
+ lambda { @selector.generate('blarf', 'gnorf') }.should raise_error(Picky::Generators::NotFoundException)
33
+ end
34
+ it "should not raise on the right params" do
35
+ @selector.stub! :generator_for_class => stub(:generator, :generate => nil)
36
+
37
+ lambda { @selector.generate('sinatra_client', 'some_project') }.should_not raise_error
38
+ end
39
+ end
40
+ end
41
+
42
+ end
@@ -0,0 +1,35 @@
1
+ # encoding: utf-8
2
+ #
3
+ require 'spec_helper'
4
+
5
+ describe Picky::Generators::Server::Unicorn do
6
+
7
+ before(:each) do
8
+ @unicorn = Picky::Generators::Server::Unicorn.new :unicorn_server, 'unicorn_server_dir_name'
9
+ @unicorn.stub! :exclaim
10
+ end
11
+
12
+ context "after initialize" do
13
+ it 'has the right identifier' do
14
+ @unicorn.identifier.should == :unicorn_server
15
+ end
16
+ it 'has the right name' do
17
+ @unicorn.name.should == 'unicorn_server_dir_name'
18
+ end
19
+ it 'has the right prototype dir' do
20
+ @unicorn.prototype_basedir.should == File.expand_path('../../../../../../prototypes/server/unicorn', __FILE__)
21
+ end
22
+ end
23
+
24
+ describe "generate" do
25
+ it "should do things in order" do
26
+ @unicorn.should_receive(:exclaim).once.ordered # Initial explanation
27
+ @unicorn.should_receive(:create_target_directory).once.ordered
28
+ @unicorn.should_receive(:copy_all_files).once.ordered
29
+ @unicorn.should_receive(:exclaim).at_least(9).times.ordered # Some user steps to do
30
+
31
+ @unicorn.generate
32
+ end
33
+ end
34
+
35
+ end
metadata ADDED
@@ -0,0 +1,147 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: picky-generators
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 1
7
+ - 1
8
+ - 0
9
+ version: 1.1.0
10
+ platform: ruby
11
+ authors:
12
+ - Florian Hanke
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-12-12 00:00:00 +01:00
18
+ default_executable: picky-generate
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rspec
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 0
30
+ version: "0"
31
+ type: :development
32
+ version_requirements: *id001
33
+ - !ruby/object:Gem::Dependency
34
+ name: picky
35
+ prerelease: false
36
+ requirement: &id002 !ruby/object:Gem::Requirement
37
+ none: false
38
+ requirements:
39
+ - - ~>
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 1
43
+ - 1
44
+ - 0
45
+ version: 1.1.0
46
+ type: :runtime
47
+ version_requirements: *id002
48
+ - !ruby/object:Gem::Dependency
49
+ name: picky-client
50
+ prerelease: false
51
+ requirement: &id003 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ~>
55
+ - !ruby/object:Gem::Version
56
+ segments:
57
+ - 1
58
+ - 1
59
+ - 0
60
+ version: 1.1.0
61
+ type: :runtime
62
+ version_requirements: *id003
63
+ description: Generators for Picky.
64
+ email: florian.hanke+picky-generators@gmail.com
65
+ executables:
66
+ - picky-generate
67
+ extensions: []
68
+
69
+ extra_rdoc_files: []
70
+
71
+ files:
72
+ - lib/picky-generators/generators/base.rb
73
+ - lib/picky-generators/generators/client/sinatra.rb
74
+ - lib/picky-generators/generators/not_found_exception.rb
75
+ - lib/picky-generators/generators/selector.rb
76
+ - lib/picky-generators/generators/server/unicorn.rb
77
+ - lib/picky-generators.rb
78
+ - prototypes/client/sinatra/app.rb
79
+ - prototypes/client/sinatra/book.rb
80
+ - prototypes/client/sinatra/config.ru
81
+ - prototypes/client/sinatra/Gemfile
82
+ - prototypes/client/sinatra/images/picky.png
83
+ - prototypes/client/sinatra/javascripts/jquery-1.3.2.js
84
+ - prototypes/client/sinatra/javascripts/jquery-1.4.3.min.js
85
+ - prototypes/client/sinatra/javascripts/jquery.scrollTo-1.4.2.js
86
+ - prototypes/client/sinatra/javascripts/jquery.timer.js
87
+ - prototypes/client/sinatra/javascripts/picky.min.js
88
+ - prototypes/client/sinatra/library.csv
89
+ - prototypes/client/sinatra/stylesheets/stylesheet.css
90
+ - prototypes/client/sinatra/stylesheets/stylesheet.sass
91
+ - prototypes/client/sinatra/views/configure.haml
92
+ - prototypes/client/sinatra/views/search.haml
93
+ - prototypes/server/unicorn/app/application.rb
94
+ - prototypes/server/unicorn/app/db.yml
95
+ - prototypes/server/unicorn/app/library.csv
96
+ - prototypes/server/unicorn/app/logging.rb
97
+ - prototypes/server/unicorn/app/README
98
+ - prototypes/server/unicorn/config.ru
99
+ - prototypes/server/unicorn/Gemfile
100
+ - prototypes/server/unicorn/log/README
101
+ - prototypes/server/unicorn/Rakefile
102
+ - prototypes/server/unicorn/script/console
103
+ - prototypes/server/unicorn/tmp/pids/README
104
+ - prototypes/server/unicorn/tmp/README
105
+ - prototypes/server/unicorn/unicorn.ru
106
+ - spec/lib/picky-generators/generators/base_spec.rb
107
+ - spec/lib/picky-generators/generators/client/sinatra_spec.rb
108
+ - spec/lib/picky-generators/generators/selector_spec.rb
109
+ - spec/lib/picky-generators/generators/server/unicorn_spec.rb
110
+ - bin/picky-generate
111
+ has_rdoc: true
112
+ homepage: http://floere.github.com/picky
113
+ licenses: []
114
+
115
+ post_install_message:
116
+ rdoc_options: []
117
+
118
+ require_paths:
119
+ - lib
120
+ required_ruby_version: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ segments:
126
+ - 0
127
+ version: "0"
128
+ required_rubygems_version: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ segments:
134
+ - 0
135
+ version: "0"
136
+ requirements: []
137
+
138
+ rubyforge_project: http://rubyforge.org/projects/picky
139
+ rubygems_version: 1.3.7
140
+ signing_key:
141
+ specification_version: 3
142
+ summary: Generators for Picky the Ruby Search Engine.
143
+ test_files:
144
+ - spec/lib/picky-generators/generators/base_spec.rb
145
+ - spec/lib/picky-generators/generators/client/sinatra_spec.rb
146
+ - spec/lib/picky-generators/generators/selector_spec.rb
147
+ - spec/lib/picky-generators/generators/server/unicorn_spec.rb