picky-client 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/picky-client.rb CHANGED
@@ -1,8 +1,6 @@
1
- $KCODE = 'UTF-8' unless RUBY_VERSION > '1.8.7'
1
+ $KCODE = 'UTF-8' if RUBY_VERSION < '1.9.0'
2
2
 
3
3
  require 'rubygems'
4
-
5
- # require 'active_support'
6
4
  require 'yajl'
7
5
 
8
6
  dir = File.dirname __FILE__
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 1
7
+ - 1
7
8
  - 0
8
- - 0
9
- version: 1.0.0
9
+ version: 1.1.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Florian Hanke
@@ -14,8 +14,8 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-12-09 00:00:00 +01:00
18
- default_executable: picky-client
17
+ date: 2010-12-12 00:00:00 +01:00
18
+ default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: yajl-ruby
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 0.7.8
33
33
  type: :runtime
34
34
  version_requirements: *id001
35
- description: Fast Combinatorial Ruby Search Engine Client
35
+ description: Picky Client
36
36
  email: florian.hanke+picky-client@gmail.com
37
- executables:
38
- - picky-client
37
+ executables: []
38
+
39
39
  extensions: []
40
40
 
41
41
  extra_rdoc_files:
@@ -43,7 +43,6 @@ extra_rdoc_files:
43
43
  files:
44
44
  - lib/picky-client/convenience.rb
45
45
  - lib/picky-client/engine.rb
46
- - lib/picky-client/generator.rb
47
46
  - lib/picky-client/helper.rb
48
47
  - lib/picky-client.rb
49
48
  - sinatra_prototype/app.rb
@@ -80,7 +79,6 @@ files:
80
79
  - spec/picky-client/engine_spec.rb
81
80
  - spec/picky-client/generator_spec.rb
82
81
  - spec/picky-client/helper_spec.rb
83
- - bin/picky-client
84
82
  has_rdoc: false
85
83
  homepage: http://floere.github.com/picky
86
84
  licenses: []
@@ -112,7 +110,7 @@ rubyforge_project: http://rubyforge.org/projects/picky
112
110
  rubygems_version: 1.3.7
113
111
  signing_key:
114
112
  specification_version: 3
115
- summary: picky Search Engine Client
113
+ summary: picky Ruby Search Engine Client
116
114
  test_files:
117
115
  - spec/picky-client/convenience_spec.rb
118
116
  - spec/picky-client/engine_spec.rb
data/bin/picky-client DELETED
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env ruby
2
- #
3
-
4
- begin
5
- require 'picky-client/generator'
6
- rescue LoadError => e
7
- require 'rubygems'
8
- picky_path = File.expand_path '../../lib', __FILE__
9
- $:.unshift(picky_path) if File.directory?(picky_path) && !$:.include?(picky_path)
10
- require 'picky-client/generator'
11
- end
12
-
13
- generator = Picky::Client::Generator.new
14
- generator.generate ARGV
@@ -1,180 +0,0 @@
1
- # encoding: utf-8
2
- #
3
- require 'fileutils'
4
-
5
- module Picky
6
-
7
- module Client
8
-
9
- # Thrown when no generator for the command
10
- # picky <command> <options>
11
- # is found.
12
- #
13
- class NoGeneratorException < Exception; end
14
-
15
- # This is a very simple project generator.
16
- # Not at all like Padrino's or Rails'.
17
- # (No diss, just by way of a faster explanation)
18
- #
19
- # Basically copies a prototype project into a newly generated directory.
20
- #
21
- class Generator
22
-
23
- attr_reader :types
24
-
25
- def initialize
26
- @types = {
27
- :sinatra => Project
28
- # :rails => Project
29
- }
30
- end
31
-
32
- # Run the generators with this command.
33
- #
34
- # This will "route" the commands to the right specific generator.
35
- #
36
- def generate args
37
- generator = generator_for *args
38
- generator.generate
39
- end
40
-
41
- #
42
- #
43
- def generator_for identifier, *args
44
- generator_class = types[identifier.to_sym]
45
- raise NoGeneratorException unless generator_class
46
- generator_for_class generator_class, identifier, *args
47
- end
48
-
49
- #
50
- #
51
- def generator_for_class klass, *args
52
- klass.new *args
53
- end
54
-
55
- # Generates a new Picky project.
56
- #
57
- # Example:
58
- # > picky project my_lovely_project
59
- #
60
- class Project
61
-
62
- attr_reader :name, :prototype_project_basedir
63
-
64
- def initialize identifier, name, *args
65
- @name = name
66
- @prototype_project_basedir = File.expand_path "../../../#{identifier}_prototype", __FILE__
67
- end
68
-
69
- #
70
- #
71
- def generate
72
- exclaim "Setting up Picky project \"#{name}\"."
73
- create_target_directory
74
- copy_all_files
75
- exclaim "\"#{name}\" is a great project name! Have fun :)\n"
76
- exclaim ""
77
- exclaim "Next steps:"
78
- exclaim "cd #{name}"
79
- exclaim "bundle install"
80
- exclaim "unicorn -p 3000 # (optional) Or use your favorite web server."
81
- exclaim ""
82
- end
83
-
84
- #
85
- #
86
- def create_target_directory
87
- if File.exists?(target_directory)
88
- exists target_directory
89
- else
90
- FileUtils.mkdir target_directory
91
- created target_directory
92
- end
93
- end
94
-
95
- #
96
- #
97
- def copy_all_files
98
- all_prototype_files.each do |filename|
99
- next if filename.match(/\.textile$/)
100
- copy_single_file filename
101
- end
102
- end
103
-
104
- #
105
- #
106
- def target_filename_for filename
107
- filename.gsub(%r{#{prototype_project_basedir}}, target_directory)
108
- end
109
- #
110
- #
111
- def copy_single_file filename
112
- target = target_filename_for filename
113
- if File.exists? target
114
- exists target
115
- else
116
- smart_copy filename, target
117
- end
118
- end
119
-
120
- # Well, "smart" ;)
121
- #
122
- def smart_copy filename, target
123
- # p "Trying to copy #{filename} -> #{target}"
124
- FileUtils.copy_file filename, target
125
- created target
126
- rescue Errno::EISDIR
127
- # p "EISDIR #{filename} -> #{target}"
128
- FileUtils.rm target
129
- FileUtils.mkdir_p target unless Dir.exists?(target)
130
- created target
131
- rescue Errno::EEXIST
132
- # p "EEXIST #{filename} -> #{target}"
133
- exists target
134
- rescue Errno::ENOTDIR
135
- # p "ENOTDIR #{filename} -> #{target}"
136
- FileUtils.mkdir_p File.dirname(target) rescue nil
137
- retry
138
- rescue Errno::ENOENT => e
139
- # p "ENOENT #{filename} -> #{target}"
140
- if File.exists? filename
141
- FileUtils.mkdir_p File.dirname(target)
142
- retry
143
- else
144
- raise e
145
- end
146
- end
147
-
148
- #
149
- #
150
- def all_prototype_files
151
- Dir[File.join(prototype_project_basedir, '**', '*')]
152
- end
153
-
154
- #
155
- #
156
- def target_directory
157
- File.expand_path name, Dir.pwd
158
- end
159
-
160
- def created entry
161
- exclaim "#{entry} \x1b[32mcreated\x1b[m."
162
- end
163
-
164
- def exists entry
165
- exclaim "#{entry} \x1b[31mexists\x1b[m, skipping."
166
- end
167
-
168
- # TODO Remove?
169
- #
170
- def exclaim something
171
- puts something
172
- end
173
-
174
- end
175
-
176
- end
177
-
178
- end
179
-
180
- end