radiant-ray-extension 3.0.0.alpha → 3.0.0.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (81) hide show
  1. data/README.markdown +1 -1
  2. data/Rakefile +2 -0
  3. data/doc/NilClass.html +178 -0
  4. data/doc/Ray/CLI.html +211 -197
  5. data/doc/Ray/Extension/Git.html +435 -0
  6. data/doc/Ray/Extension/RubyGem.html +858 -0
  7. data/doc/Ray/Extension/Zip.html +453 -0
  8. data/doc/Ray/Extension.html +755 -0
  9. data/doc/Ray/{Cache.html → Search/Cache.html} +108 -256
  10. data/doc/Ray/{GitHub.html → Search/GitHub.html} +167 -81
  11. data/doc/Ray/{RubyGems.html → Search/RubyGems.html} +118 -68
  12. data/doc/Ray/Search.html +822 -0
  13. data/doc/Ray.html +89 -34
  14. data/doc/String.html +99 -29
  15. data/doc/_index.html +1 -1
  16. data/doc/file.LICENSE.html +1 -1
  17. data/doc/file.README.html +2 -4
  18. data/doc/index.html +1 -1
  19. data/doc/top-level-namespace.html +3 -3
  20. data/lib/ray/cli.rb +146 -193
  21. data/lib/ray/constants.rb +7 -12
  22. data/lib/ray/extension.rb +203 -89
  23. data/lib/ray/search.rb +198 -43
  24. data/lib/ray/utility.rb +31 -0
  25. data/lib/ray.rb +2 -7
  26. data/spec/fixtures/cache_single.yml +2 -1
  27. data/spec/fixtures/cassettes/combined_search_empty.yml +71 -0
  28. data/spec/fixtures/cassettes/combined_search_multiple.yml +264 -0
  29. data/spec/fixtures/cassettes/combined_search_single.yml +108 -0
  30. data/spec/fixtures/cassettes/github_reorder_children_zip_file.yml +487 -0
  31. data/spec/fixtures/cassettes/github_sitemap_xml_zip_file.yml +553 -0
  32. data/spec/fixtures/cassettes/{github_v2_api_no_matches.yml → github_v2_search_empty.yml} +3 -3
  33. data/spec/fixtures/cassettes/github_v2_search_multiple.yml +225 -0
  34. data/spec/fixtures/cassettes/github_v2_search_single.yml +76 -0
  35. data/spec/fixtures/cassettes/{zip_file.yml → github_zip_file.yml} +3 -3
  36. data/spec/fixtures/cassettes/{rubygems_v1_api_gem_info.yml → rubygems_v1_gem_info.yml} +5 -5
  37. data/spec/fixtures/cassettes/{rubygems_v1_api_no_matches.yml → rubygems_v1_search_empty.yml} +3 -3
  38. data/spec/fixtures/cassettes/rubygems_v1_search_multiple.yml +40 -0
  39. data/spec/fixtures/cassettes/{rubygems_v1_api_search_reorder_children.yml → rubygems_v1_search_single.yml} +6 -6
  40. data/spec/fixtures/dummy.zip +0 -0
  41. data/spec/ray/extension_spec.rb +172 -0
  42. data/spec/ray/search_spec.rb +300 -0
  43. data/spec/spec_helper.rb +36 -9
  44. metadata +50 -85
  45. data/doc/Extension.html +0 -1189
  46. data/doc/Ray/Gem.html +0 -760
  47. data/doc/Ray/Git.html +0 -278
  48. data/doc/Ray/Zip.html +0 -300
  49. data/doc/Search.html +0 -433
  50. data/lib/ray/extension/gem.rb +0 -96
  51. data/lib/ray/extension/git.rb +0 -30
  52. data/lib/ray/extension/zip.rb +0 -44
  53. data/lib/ray/search/cache.rb +0 -61
  54. data/lib/ray/search/github.rb +0 -40
  55. data/lib/ray/search/rubygems.rb +0 -36
  56. data/lib/ray/string.rb +0 -18
  57. data/spec/fixtures/Gemfile +0 -4
  58. data/spec/fixtures/cassettes/github_v2_api_search_no_matches.yml +0 -38
  59. data/spec/fixtures/cassettes/github_v2_api_search_reorder_children.yml +0 -75
  60. data/spec/fixtures/cassettes/github_v2_api_search_single.yml +0 -74
  61. data/spec/fixtures/cassettes/github_v3_api_owner_name.yml +0 -75
  62. data/spec/fixtures/cassettes/rubygems_v1_api_search_no_matches.yml +0 -34
  63. data/spec/fixtures/cassettes/rubygems_v1_api_search_reorder.yml +0 -36
  64. data/spec/fixtures/cassettes/rubygems_v1_api_search_single.yml +0 -41
  65. data/spec/fixtures/dummy/README +0 -1
  66. data/spec/fixtures/dummy/Rakefile +0 -109
  67. data/spec/fixtures/dummy/config/initializers/radiant_config.rb +0 -3
  68. data/spec/fixtures/dummy/config/locales/en.yml +0 -3
  69. data/spec/fixtures/dummy/config/routes.rb +0 -5
  70. data/spec/fixtures/dummy/dummy_extension.rb +0 -21
  71. data/spec/fixtures/dummy/lib/radiant-dummy-extension.rb +0 -8
  72. data/spec/fixtures/dummy/lib/tasks/dummy_extension_tasks.rake +0 -47
  73. data/spec/fixtures/dummy/public/stylesheets/extensions/dummy/dummy.css +0 -0
  74. data/spec/fixtures/dummy/radiant-dummy-extension.gemspec +0 -29
  75. data/spec/ray/extension/gem_spec.rb +0 -214
  76. data/spec/ray/extension/git_spec.rb +0 -216
  77. data/spec/ray/extension/zip_spec.rb +0 -239
  78. data/spec/ray/search/cache_spec.rb +0 -74
  79. data/spec/ray/search/github_spec.rb +0 -137
  80. data/spec/ray/search/rubygems_spec.rb +0 -127
  81. data/spec/ray/string_spec.rb +0 -30
data/lib/ray/extension.rb CHANGED
@@ -1,116 +1,230 @@
1
- require "fileutils"
1
+ require "multi_json"
2
2
  require "open-uri"
3
3
  require "rake"
4
- require "ray/string"
5
-
6
- module Extension
7
-
8
- attr_accessor :author,
9
- :description,
10
- :homepage,
11
- :name,
12
- :uri,
13
- :version
14
-
15
- def initialize options = {}
16
- @author = options[:author]
17
- @description = options[:description]
18
- @homepage = options[:homepage]
19
- @name = options[:name].to_s.to_extension_name
20
- @uri = options[:uri]
21
- @version = options[:version]
22
- end
4
+ require "zip"
5
+ require "ray/utility"
23
6
 
24
- def disable
25
- unless File.exist? "#{Ray::EXT_DIR}/#{@name}"
26
- raise "The #{@name} extension is not installed"
27
- end
7
+ module Ray
28
8
 
29
- FileUtils.mkdir_p "#{Ray::EXT_DIR}/.disabled"
30
- FileUtils.mv "#{Ray::EXT_DIR}/#{@name}", "#{Ray::EXT_DIR}/.disabled/#{@name}"
31
- end
9
+ # Install extensions from RubyGems, GitHub or zip files
10
+ class Extension
32
11
 
33
- def enable
34
- unless File.exist? "#{Ray::EXT_DIR}/.disabled/#{@name}"
35
- raise "The #{@name} extension is not disabled"
12
+ attr_accessor :name, :uri
13
+
14
+ def initialize name = nil, uri = nil
15
+ @name = name.to_extension_name
16
+ @uri = uri
36
17
  end
37
18
 
38
- FileUtils.mv "#{Ray::EXT_DIR}/.disabled/#{@name}", "#{Ray::EXT_DIR}/#{@name}"
39
- end
19
+ # Download file to tmp/ray/tempfile
20
+ def download
21
+ # set StringMax to 0 so open-uri always creates a tmp file
22
+ OpenURI::Buffer.send :remove_const, "StringMax"
23
+ OpenURI::Buffer.const_set "StringMax", 0
40
24
 
41
- def uninstall
42
- unless File.exist? "#{Ray::EXT_DIR}/#{@name}"
43
- raise "The #{@name} extension is not installed"
25
+ FileUtils.mkdir_p TMP
26
+ tmpfile = open(@uri).path
27
+ FileUtils.cp tmpfile, "#{TMP}/#{@uri.split('/').last}"
44
28
  end
45
29
 
46
- run_tasks({
47
- :migrate => "VERSION=0",
48
- :update => :psa
49
- })
50
- FileUtils.rm_rf "#{Ray::EXT_DIR}/#{@name}"
51
- end
30
+ # Move extension to vendor/extensions/name and run Rake tasks
31
+ def install
32
+ dir = Dir.glob("#{TMP}/*").reject { |f| File.ftype(f) != "directory" }
33
+ FileUtils.mv dir.first, "#{EXT_DIR}/#{@name}"
34
+ FileUtils.rm_r TMP
35
+ run_rake_tasks
36
+ end
52
37
 
53
- def download
54
- raise "The extension name is required" unless @name
55
- raise "The extension URI is required" unless @uri
38
+ def disable
39
+ FileUtils.mkdir_p "#{EXT_DIR}/.disabled"
40
+ FileUtils.mv "#{EXT_DIR}/#{@name}", "#{EXT_DIR}/.disabled/#{@name}"
41
+ end
56
42
 
57
- puts "#{@name} => Downloading..."
58
- FileUtils.mkdir_p Ray::TMP_DIR
59
- tmpfile = open(@uri).path
60
- FileUtils.cp tmpfile, "#{Ray::TMP_DIR}/#{@uri.split('/').last}"
61
- end
43
+ def enable
44
+ FileUtils.mv "#{EXT_DIR}/.disabled/#{@name}", "#{EXT_DIR}/#{@name}"
45
+ end
62
46
 
63
- def vendor
64
- puts "#{@name} => Vendoring..."
65
- directory = Dir.glob("#{Ray::TMP_DIR}/*").first
66
- FileUtils.mv directory, "#{Ray::EXT_DIR}/#{@name}"
67
- end
47
+ def uninstall
48
+ tasks = load_rake_tasks
49
+ tasks.each do |task|
50
+ case task
51
+ when "radiant:extensions:#{@name}:uninstall"
52
+ run_task "uninstall"
53
+ break
54
+ when "radiant:extensions:#{@name}:migrate"
55
+ run_task "migrate", "VERSION=0"
56
+ when "radiant:extensions:#{@name}:update"
57
+ public_service_announcement
58
+ end
59
+ end
60
+ disable
61
+ end
68
62
 
69
- def run_tasks options = { :migrate => "", :update => "" }
70
- tasks = load_tasks
71
- tasks.each do |task|
72
- case task
73
- when "radiant:extensions:#{@name}:install"
74
- run_task "install"
75
- break
76
- when "radiant:extensions:#{@name}:migrate"
77
- run_task "migrate", options[:migrate]
78
- when "radiant:extensions:#{@name}:update"
79
- run_task "update", options[:update]
63
+ def public_service_announcement
64
+ path = "#{EXT_DIR}/#{@name}"
65
+ stuff_in_public = Dir.glob("#{path}/public/**/*.*").each do |f|
66
+ f.sub!(/#{path}\//, "")
67
+ end
68
+ %Q{
69
+ # The #{@name} extension added the following files to the public directory:
70
+ # #{stuff_in_public.join("\n# ")}
71
+ # These files were not deleted in case some other extension might need them.
72
+ }.lstrip unless stuff_in_public.empty?
73
+ end
74
+
75
+ # Load and run appropriate Rake tasks
76
+ def run_rake_tasks
77
+ tasks = load_rake_tasks
78
+ tasks.each do |task|
79
+ case task
80
+ when "radiant:extensions:#{@name}:install"
81
+ run_task "install"
82
+ break
83
+ when "radiant:extensions:#{@name}:migrate"
84
+ run_task "migrate"
85
+ when "radiant:extensions:#{@name}:update"
86
+ run_task "update"
87
+ end
80
88
  end
81
89
  end
82
- end
83
90
 
84
- def run_task task, options = {}
85
- puts "#{@name} => Running #{task} task..."
86
- if task == "update" and options == :psa
87
- public_service_announcement
88
- else
91
+ # Run a specific Rake task
92
+ def run_task(task, options = "")
89
93
  `rake radiant:extensions:#{@name}:#{task} #{options}`
90
94
  end
91
- end
92
95
 
93
- def load_tasks
94
- puts "#{@name} => Loading tasks..."
95
- rake_file = "#{Ray::ROOT}/vendor/extensions/#{@name}/lib/tasks/#{@name}_extension_tasks.rake"
96
- load rake_file if File.exist? rake_file
97
- Rake.application.tasks.map(&:name)
98
- end
96
+ # Load Rakefile
97
+ # @return [Array] List of available tasks
98
+ def load_rake_tasks
99
+ rake_file = "#{ROOT}/vendor/extensions/#{@name}/lib/tasks/#{@name}_extension_tasks.rake"
100
+ load rake_file if File.exist? rake_file
101
+ Rake.application.tasks.map(&:name)
102
+ end
99
103
 
100
- def cleanup
101
- puts "#{@name} => Removing temporary files..."
102
- FileUtils.rm_rf Ray::TMP_DIR
103
- end
104
+ # Install extensions from zip files
105
+ class Zip < Extension
106
+
107
+ # Extract downloaded zip file to tmp/ray/tempfile
108
+ def extract
109
+ begin
110
+ ::Zip::ZipFile.open Dir.glob("#{TMP}/*").first do |zip_file|
111
+ zip_file.each do |f|
112
+ f_path = File.join "#{TMP}", f.name
113
+ FileUtils.mkdir_p File.dirname f_path
114
+ zip_file.extract f, f_path unless File.exist? f_path
115
+ end
116
+ end
117
+ rescue ::Zip::ZipError
118
+ # just for fun let's try gem unpack!
119
+ Dir.chdir TMP do
120
+ `gem unpack #{@uri.split('/').last}`
121
+ end
122
+ end
123
+ end
124
+
125
+ end
126
+
127
+ # Install extensions from Git repositories
128
+ class Git < Extension
129
+
130
+ # Clone repository to tmp/ray/tempfile
131
+ def clone
132
+ FileUtils.mkdir_p TMP
133
+ Dir.chdir TMP do
134
+ `git clone --depth=1 --quiet #{@uri} #{@name}`
135
+ FileUtils.rm_rf "#{@name}/.git"
136
+ end
137
+ end
138
+
139
+ end
140
+
141
+ # Install extensions from RubyGems
142
+ class RubyGem < Extension
143
+
144
+ attr_accessor :name, :uri, :version
145
+
146
+ def initialize name = nil, uri = nil, version = nil
147
+ @name = name.to_extension_name
148
+ @uri = uri
149
+ @version = version || get_version if @name
150
+ end
151
+
152
+ # Bundle extension
153
+ def bundle
154
+ File.open GEMFILE, "a" do |gemfile|
155
+ gemfile.puts "gem \"radiant-#{@name}-extension\", \"#{@version}\""
156
+ end
157
+ `bundle update`
158
+ end
159
+ alias enable bundle
160
+
161
+ # copy and run Rake tasks
162
+ def install
163
+ path = `bundle show radiant-#{@name}-extension`.chomp
164
+ begin
165
+ FileUtils.cp "#{path}/lib/tasks/#{@name}_extension_tasks.rake", "#{ROOT}/lib/tasks/"
166
+ rescue
167
+ end
168
+ run_rake_tasks
169
+ end
170
+
171
+ def disable
172
+ current = File.read GEMFILE
173
+ updated = current.sub /gem "radiant-#{@name}-extension".+\n/, ""
174
+ File.open GEMFILE, "w" do |gemfile|
175
+ gemfile.puts updated
176
+ end
177
+ FileUtils.rm "#{GEMFILE}.lock"
178
+ `bundle update`
179
+ end
180
+
181
+ # def enable
182
+ # bundle
183
+ # end
184
+
185
+ def uninstall
186
+ tasks = load_rake_tasks
187
+ tasks.each do |task|
188
+ case task
189
+ when "radiant:extensions:#{@name}:uninstall"
190
+ run_task "uninstall"
191
+ break
192
+ when "radiant:extensions:#{@name}:migrate"
193
+ run_task "migrate", "VERSION=0"
194
+ when "radiant:extensions:#{@name}:update"
195
+ public_service_announcement
196
+ end
197
+ end
198
+ disable
199
+ end
200
+
201
+ # Load Rakefile
202
+ # @return [Array] List of available tasks
203
+ def load_rake_tasks
204
+ rake_file = "#{ROOT}/lib/tasks/#{@name}_extension_tasks.rake"
205
+ load rake_file if File.exist? rake_file
206
+ Rake.application.tasks.map(&:name)
207
+ end
208
+
209
+ def get_version
210
+ uri = "http://rubygems.org/api/v1/gems/radiant-#{@name}-extension.json"
211
+ return "~> #{MultiJson.decode(open(uri).read)['version']}"
212
+ end
213
+
214
+ def public_service_announcement
215
+ path = `bundle show radiant-#{@name}-extension`.chop
216
+ stuff_in_public = Dir.glob("#{path}/public/**/*.*").each do |f|
217
+ f.sub!(/#{path}\//, "")
218
+ end
219
+ %Q{
220
+ # The #{@name} extension added the following files to the public directory:
221
+ # #{stuff_in_public.join("\n# ")}
222
+ # These files were not deleted in case some other extension might need them.
223
+ }.lstrip unless stuff_in_public.empty?
224
+ end
104
225
 
105
- def public_service_announcement path = nil
106
- path ||= "#{Ray::EXT_DIR}/#{@name}"
107
- Dir.glob("#{path}/public/**/*.*").each do |f|
108
- FileUtils.rm_rf File.expand_path(f.sub! /#{path}\//, "")
109
226
  end
110
- end
111
227
 
112
- def name= name
113
- @name = name.to_extension_name
114
228
  end
115
229
 
116
230
  end
data/lib/ray/search.rb CHANGED
@@ -1,62 +1,217 @@
1
- require "fileutils"
2
1
  require "multi_json"
3
2
  require "open-uri"
4
- require "ray/string"
3
+ require "ray/utility"
5
4
  require "yaml"
6
5
 
7
- module Search
6
+ module Ray
8
7
 
9
- def search
10
- normalize open(@uri).read
11
- end
8
+ # Search RubyGems, GitHub and/or the local cache for extension information
9
+ class Search
10
+
11
+ attr_reader :query,
12
+ :results,
13
+ :uri
12
14
 
13
- def cache
14
- if File.exist? Ray::CACHE
15
- cache = YAML.load_file Ray::CACHE
16
- else
17
- FileUtils.mkdir_p Ray::RAY
18
- FileUtils.touch Ray::CACHE
19
- cache = {}
15
+ def initialize query = nil, live = nil
16
+ if query
17
+ @query = query
18
+ @results = live ? {} : Cache.new(query).results
19
+ if @results.empty?
20
+ rubygems = RubyGems.new query
21
+ github = GitHub.new query
22
+ @results = github.results.merge rubygems.results
23
+ @uri = [rubygems.uri, github.uri]
24
+ end
25
+ else
26
+ @results = "A search query is required. Try: ray help search"
27
+ end
20
28
  end
21
- File.open Ray::CACHE, "w" do |f|
22
- f.write cache.merge(@results).to_yaml
29
+
30
+ # Write search results to local cache file
31
+ # @return [Hash] the original search results
32
+ def cache
33
+ if @results.respond_to? :merge
34
+ if File.exist? CACHE
35
+ cache = YAML.load_file CACHE
36
+ else
37
+ FileUtils.mkdir_p RAY
38
+ FileUtils.touch CACHE
39
+ cache = {}
40
+ end
41
+ File.open CACHE, "w" do |f|
42
+ f.write cache.merge(@results).to_yaml
43
+ end
44
+ end
45
+ return self
23
46
  end
24
- return self
25
- end
26
47
 
27
- def output
28
- output = ""
29
- if @results.empty?
30
- output += %Q{
31
- No extensions matched: #{@query}
32
- # URI: #{@uri}
33
- }.lstrip
34
- else
35
- @results.each do |extension|
36
- name = extension.first.to_extension_name
37
- info = extension.last
38
- output += %Q{
48
+ # Pretty printable string; optimized for CLI
49
+ # @return [String] pretty text ready for output
50
+ def output
51
+ if @results =~ /query is required/
52
+ @results
53
+ elsif @results.empty?
54
+ "No extensions matched '#{@query}'"
55
+ else
56
+ output = ""
57
+ @results.each do |extension|
58
+ name = extension.first.to_extension_name
59
+ info = extension.last
60
+ output += %Q{
39
61
  #{"-" * 80}
40
- #{name} (#{info[:version]}) by #{info[:author][0..(78 - " #{name} (#{info[:version]}) by ".size)]}
62
+ #{name} (#{info[:version]}) by #{info[:author][0..(78 - " #{name} (#{info[:version]}) by ".size)]}
41
63
  #{info[:description].wrap(78, 2)}
42
- #{info[:homepage]}
43
- ray install #{name}\n
64
+ #{info[:homepage]}
65
+ ray install #{name}\n
44
66
  }.lstrip
67
+ end
68
+ return output
45
69
  end
46
- return output
47
70
  end
48
- end
49
71
 
50
- def multiple_choice
51
- puts output
52
- print "Which extension do you want to install? "
53
- choice = STDIN.gets.chomp
54
- @results[choice]
55
- end
72
+ # Prompt the user to choose from a list of possible extensions
73
+ # @return [Hash] Extension information
74
+ def multiple_choice
75
+ puts output
76
+ print "Which extension do you want to install? "
77
+ choice = STDIN.gets.chomp
78
+ @results[choice]
79
+ end
80
+
81
+ # Get raw JSON response from search providers
82
+ # @return [Hash] search results in a normalized format
83
+ def search
84
+ normalize open(@uri).read
85
+ end
86
+
87
+ # Search RubyGems for extension information
88
+ class RubyGems < Search
89
+
90
+ attr_reader :query,
91
+ :results,
92
+ :uri
93
+
94
+ def initialize query = nil
95
+ if query
96
+ @query = query
97
+ @uri = "https://rubygems.org/api/v1/search.json?query=radiant-#{query}"
98
+ @results = search
99
+ else
100
+ @results = "A search query is required. Try: ray help search"
101
+ end
102
+ end
103
+
104
+ # Normalize RubyGems JSON response
105
+ # @return [Hash] search results in a normalized format
106
+ def normalize response
107
+ response = MultiJson.decode response
108
+ results = {}
109
+ response.each do |extension|
110
+ results[extension["name"].to_extension_name] = {
111
+ :author => extension["authors"],
112
+ :description => extension["info"],
113
+ :homepage => extension["homepage_uri"],
114
+ :name => extension["name"].to_extension_name,
115
+ :repository => extension["source_code_uri"],
116
+ :uri => extension["gem_uri"],
117
+ :version => extension["version"]
118
+ }
119
+ end
120
+ return results
121
+ end
122
+
123
+ end
124
+
125
+ # Search GitHub for extension information
126
+ class GitHub < Search
127
+
128
+ attr_reader :query,
129
+ :results,
130
+ :uri
131
+
132
+ def initialize query = nil
133
+ if query
134
+ @query = query
135
+ @uri = "http://github.com/api/v2/json/repos/search/radiant+#{query}"
136
+ @results = search
137
+ else
138
+ @results = "A search query is required. Try: ray help search"
139
+ end
140
+ end
141
+
142
+ # Normalize GitHub JSON response
143
+ # @return [Hash] search results in a normalized format
144
+ def normalize response
145
+ response = MultiJson.decode response
146
+ results = {}
147
+ response["repositories"].each do |extension|
148
+ results[extension["name"].to_extension_name] = {
149
+ :author => real_name(extension["owner"]),
150
+ :description => extension["description"],
151
+ :homepage => extension["url"],
152
+ :name => extension["name"].to_extension_name,
153
+ :repository => "#{extension['url']}.git",
154
+ :uri => "#{extension['url']}/zipball/master",
155
+ :version => "latest"
156
+ }
157
+ end
158
+ return results
159
+ end
160
+
161
+ # Use GitHub API v3 to look up the owner's real name
162
+ # @return [String] the owner's real name
163
+ # @example
164
+ # real_name "saturnflyer" # => "Jim Gay"
165
+ def real_name owner
166
+ response = open("https://api.github.com/users/#{owner}").read
167
+ MultiJson.decode(response)["name"]
168
+ end
169
+
170
+ end
171
+
172
+ # Search the local cache for extension information
173
+ class Cache < Search
174
+
175
+ attr_reader :query,
176
+ :results,
177
+ :uri
178
+
179
+ def initialize query = nil
180
+ if query
181
+ @query = query
182
+ @uri = "file:///#{CACHE}"
183
+ @results = search
184
+ else
185
+ @results = "A search query is required. Try: ray help search"
186
+ end
187
+ end
188
+
189
+ # Override Search#search to use the local cache
190
+ # @return [Hash] local search results
191
+ def search
192
+ return {} unless File.exist? CACHE
193
+ cache = YAML.load_file CACHE
194
+ results = {}
195
+ cache.each do |extension|
196
+ name = extension.first
197
+ info = extension.last
198
+ if "#{name} #{info[:description]}".include? @query
199
+ results[name] = {
200
+ :author => info[:author],
201
+ :description => info[:description],
202
+ :homepage => info[:homepage],
203
+ :name => name,
204
+ :repository => info[:repository],
205
+ :uri => info[:uri],
206
+ :version => info[:version]
207
+ }
208
+ end
209
+ end
210
+ return results
211
+ end
212
+
213
+ end
56
214
 
57
- def merge other
58
- self.results.merge! other.results
59
- return self
60
215
  end
61
216
 
62
217
  end
@@ -0,0 +1,31 @@
1
+ # String extensions
2
+ class String
3
+
4
+ # Turns pretty much any string into a "proper" extension name
5
+ # @return [String] the string converted to an extension name
6
+ # @example
7
+ # "radiant-example-extension".to_extension_name # => example
8
+ # "radiant-my-ext-extension".to_extension_name # => my_ext
9
+ # "monkey-patches".to_extension_name # => monkey_patches
10
+ # "nice_name".to_extension_name # => nice_name
11
+ def to_extension_name
12
+ name = self.gsub /radiant[-_]/i, ""
13
+ name.gsub! /[-_]extension/i, ""
14
+ name.gsub! /-/, "_"
15
+ return name
16
+ end
17
+
18
+ # Wrap, indent and flare text output
19
+ # @return [String] the string after mangling
20
+ def wrap columns = 80, indent = 0, prefix = ""
21
+ indent = " " * indent
22
+ self.gsub(/(.{1,#{columns}})( +|$\n?)|(.{1,#{columns}})/,"#{prefix}#{indent}\\1\\3\n")
23
+ end
24
+
25
+ end
26
+
27
+ class NilClass
28
+ def to_extension_name
29
+ nil
30
+ end
31
+ end
data/lib/ray.rb CHANGED
@@ -1,8 +1,3 @@
1
1
  require "ray/constants"
2
- require "ray/extension/gem"
3
- require "ray/extension/git"
4
- require "ray/extension/zip"
5
- require "ray/search/cache"
6
- require "ray/search/github"
7
- require "ray/search/rubygems"
8
- require "ray/string"
2
+ require "ray/extension"
3
+ require "ray/search"
@@ -2,7 +2,8 @@
2
2
  reorder_children:
3
3
  :author: Benny Degezelle
4
4
  :description: Makes Radiant better by adding reorder_children!
5
+ :uri: http://rubygems.org/gems/radiant-reorder_children-extension-1.0.5.gem
5
6
  :homepage: http://github.com/jomz/radiant-reorder_children-extension
6
7
  :name: reorder_children
7
- :uri: http://rubygems.org/gems/radiant-reorder_children-extension-1.0.5.gem
8
+ :repository:
8
9
  :version: 1.0.5