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/cli.rb CHANGED
@@ -3,264 +3,217 @@ require "ray"
3
3
 
4
4
  module Ray
5
5
 
6
- # This is the CLI for Ray.
7
- # If you're trying to figure out how to use the Ray CLI
8
- # refer to the [User Manual](http://goo.gl/5UtP8) instead.
6
+ # Ray's command line interface.
7
+ # See the [User Manual](http://johnmuhl.github.com/radiant-ray-extension/)
8
+ # for complete command line usage.
9
9
  class CLI < Thor
10
10
 
11
11
  include Thor::Actions
12
12
  include Thor::Shell
13
13
 
14
- no_tasks do
15
- def self.man task
16
- %Q{
17
- See also
18
- http://johnmuhl.github.com/radiant-ray-extension##{task.to_s}
19
- }
20
- end
21
- end
22
-
23
- map "-v" => "version"
24
-
25
14
  default_task :help
26
15
 
27
- desc "version", "Display your current version of Ray"
16
+ desc "version", "Current version of Ray"
28
17
  def version
29
- say "Friendly extension management for Radiant CMS"
30
- say "Version: #{Ray::VERSION}"
18
+ say Ray::VERSION
31
19
  end
32
20
 
33
- desc "search [QUERY]", "Search for extensions"
34
- long_desc %Q{
35
- By default, search will check the local cache before making any network
36
- requests. If no matches are found in the cache GitHub and Rubygems are
37
- searched. If an extension is found on both GitHub and RubyGems the
38
- information from RubyGems is used. Use the --github and --rubygems flags
39
- to restrict your search or the --live flag to bypass the local cache.
40
-
41
- #{man :search}
42
- }
43
- method_option :github,
44
- :aliases => "-g",
45
- :desc => "Only search GitHub",
46
- :type => :boolean
47
- method_option :rubygems,
48
- :aliases => "-r",
49
- :desc => "Only search RubyGems",
50
- :type => :boolean
51
- method_option :live,
52
- :aliases => "-l",
53
- :desc => "Bypass local cache",
54
- :type => :boolean
55
- def search query
21
+ desc "search [QUERY]", "Search for extensions by name or keyword"
22
+ method_option :github, :desc => "Restrict search to GitHub",
23
+ :aliases => "-g", :type => :boolean
24
+ method_option :rubygems, :desc => "Restrict search to RubyGems",
25
+ :aliases => "-r", :type => :boolean
26
+ method_option :live, :desc => "Bypass local cache",
27
+ :aliases => "-l", :type => :boolean
28
+ # Search for extensions
29
+ # @example
30
+ # ray search blog
31
+ # ray search blog --live
32
+ # ray search blog --github
33
+ # ray search blog --rubygems
34
+ def search query = nil
56
35
  search = case
57
- when options["github"]
58
- Ray::GitHub.new query
59
36
  when options["rubygems"]
60
- Ray::RubyGems.new query
37
+ Ray::Search::RubyGems.new query
38
+ when options["github"]
39
+ Ray::Search::GitHub.new query
61
40
  when options["live"]
62
- Ray::GitHub.new(query).merge Ray::RubyGems.new(query)
63
- else
64
- if Ray::Cache.new(query).results.empty?
65
- Ray::GitHub.new(query).merge Ray::RubyGems.new(query)
66
- else
67
- Ray::Cache.new query
68
- end
41
+ Ray::Search.new query, :live
42
+ when options.empty?
43
+ Ray::Search.new query
69
44
  end
70
-
71
45
  search.cache
72
46
  say search.output
73
47
  end
74
48
 
75
- desc "install [EXTENSIONS]", "Install extensions"
76
- long_desc %Q{
77
- #{man :install}
78
- }
79
- method_option :gem,
80
- :aliases => "-r",
81
- :banner => "URL",
82
- :desc => "Install from RubyGem"
83
- method_option :git,
84
- :aliases => "-g",
85
- :banner => "URL",
86
- :desc => "Install from Git repository"
87
- method_option :zip,
88
- :aliases => "-z",
89
- :banner => "URL",
90
- :desc => "Install from zip archive"
49
+ desc "install [EXTENSION]", "Install extensions"
50
+ method_option :git, :desc => "Install extension from Git repository",
51
+ :aliases => "-g"
52
+ method_option :rubygem, :desc => "Install extension from RubyGems",
53
+ :aliases => "-r"
54
+ method_option :zip, :desc => "Install extension from zip archive",
55
+ :aliases => "-z"
56
+ # Install extensions
57
+ # @example
58
+ # ray install reorder-children
59
+ # ray install reorder-children --git
60
+ # ray install reorder-children --rubygem
61
+ # ray install reorder-children --zip
91
62
  def install *extensions
92
- if extensions.empty?
93
- say "You didn't list any extensions to install", :red
94
- say "Try: ray help install"
95
- exit 1
96
- end
97
-
98
63
  case
99
- when options["gem"] # --gem
100
- if options["gem"] == "gem" # no uri was passed to --gem
64
+ when options["zip"]
65
+ if extensions.size > 1 && options["zip"] != "zip"
66
+ say "You can only list one extension at a time", :red
67
+ exit 1
68
+ end
69
+ if options["zip"] == "zip"
101
70
  extensions.each do |extension|
102
- search = Ray::Cache.new extension # first we search the cache
103
- if search.results.empty? # when there are no cache hits
104
- search = Ray::RubyGems.new extension # then search rubygems
105
- else # when there are cache hits
106
- results = {}
107
- search.results.select do |name, info| # filter out non-gem extensions
108
- info[:uri] =~ /rubygems/
109
- end.map do |extension|
110
- results[extension.first] = extension.last # rebuild the results hash
111
- end
112
- if results.empty?
113
- search = Ray::RubyGems.new extension
114
- else
115
- search.results = results # reset the results hash
116
- end
71
+ search = Ray::Search.new extension.to_extension_name
72
+ search.cache
73
+ if search.results.size == 1
74
+ extension = search.results.first.last
75
+ else
76
+ extension = search.multiple_choice
117
77
  end
118
- if search.results.size == 1 # when there is just one match
119
- extension = Ray::Gem.new search.results.first.last # that's our extension
120
- else # when there is more than one match
121
- extension = Ray::Gem.new search.multiple_choice # make the user pick
122
- end
123
- extension.install # install the extension
124
- say "#{extension.name} => Installed!", :green
125
- end
126
- else # a uri was passed to --gem
127
- extension = Ray::Gem.new({ # instantiate with minimal info
128
- :name => extensions.first, # nothing works without a name
129
- :uri => options["gem"] # uri should be a git repo
130
- })
131
- say "#{extension.name} => Adding to Gemfile..."
132
- name = "radiant-#{extension.name}-extension"
133
- File.open Ray::GEMFILE, "a" do |gemfile|
134
- gemfile.puts "gem \"#{name}\", :git => \"#{extension.uri}\"" # add it to the gemfile
78
+ zip = Ray::Extension::Zip.new extension[:name], extension[:uri]
79
+ say "#{extension[:name]} => Downloading...", :yellow
80
+ zip.download
81
+ say "#{extension[:name]} => Extracting...", :yellow
82
+ zip.extract
83
+ say "#{extension[:name]} => Running tasks...", :yellow
84
+ zip.install
85
+ say "#{extension[:name]} => Installation complete.", :green
135
86
  end
136
- extension.bundle # we don't use install here
137
- extension.copy_tasks # because add_gem only works
138
- extension.run_tasks # with released gem extensions
139
- say "#{extension.name} => Installed!", :green
87
+ else
88
+ name = extensions.first.to_extension_name
89
+ zip = Ray::Extension::Zip.new name, options["zip"]
90
+ say "#{name} => Downloading...", :yellow
91
+ zip.download
92
+ say "#{name} => Extracting...", :yellow
93
+ zip.extract
94
+ say "#{name} => Running tasks...", :yellow
95
+ zip.install
96
+ say "#{name} => Installation complete.", :green
140
97
  end
141
98
  when options["git"]
99
+ if extensions.size > 1 && options["git"] != "git"
100
+ say "You can only list one extension at a time", :red
101
+ exit 1
102
+ end
142
103
  if options["git"] == "git"
143
104
  extensions.each do |extension|
144
- search = Ray::Cache.new extension # first we search the cache
145
- if search.results.empty? # when there are no cache hits
146
- search = Ray::GitHub.new extension # then search github
147
- else # when there are cache hits
148
- results = {}
149
- search.results.select do |name, info| # filter out non-git extensions
150
- info[:uri] =~ /github/
151
- end.map do |extension|
152
- results[extension.first] = extension.last # rebuild the results hash
153
- end
154
- if results.empty?
155
- search = Ray::GitHub.new extension
156
- else
157
- search.results = results # reset the results hash
158
- end
105
+ search = Ray::Search::GitHub.new extension.to_extension_name
106
+ search.cache
107
+ if search.results.size == 1
108
+ extension = search.results.first.last
109
+ else
110
+ extension = search.multiple_choice
159
111
  end
160
- if search.results.size == 1 # when there is just one match
161
- extension = Ray::Git.new search.results.first.last # that's our extension
162
- else # when there is more than one match
163
- extension = Ray::Git.new search.multiple_choice # make the user pick
164
- end
165
- extension.install # install the extension
166
- say "#{extension.name} => Installed!", :green
112
+ git = Ray::Extension::Git.new extension[:name], extension[:repository]
113
+ say "#{extension[:name]} => Cloning...", :yellow
114
+ git.clone
115
+ say "#{extension[:name]} => Running tasks...", :yellow
116
+ git.install
117
+ say "#{extension[:name]} => Installation complete.", :green
167
118
  end
168
119
  else
169
- extension = Ray::Git.new({ # instantiate with minimal info
170
- :name => extensions.first, # nothing works without a name
171
- :uri => options["git"] # uri should be a git repo
172
- })
173
- extension.install # install the extension
174
- say "#{extension.name} => Installed!s", :green
120
+ name = extensions.first.to_extension_name
121
+ git = Ray::Extension::Git.new name, options["git"]
122
+ say "#{name} => Cloning...", :yellow
123
+ git.clone
124
+ say "#{name} => Running tasks...", :yellow
125
+ git.install
126
+ say "#{name} => Installation complete.", :green
175
127
  end
176
- when options["zip"]
177
- if options["zip"] == "zip"
128
+ when options["rubygem"]
129
+ if extensions.size > 1 && options["rubygem"] != "rubygem"
130
+ say "You can only list one extension at a time", :red
131
+ exit 1
132
+ end
133
+ if options["rubygem"] == "rubygem"
178
134
  extensions.each do |extension|
179
- search = Ray::Cache.new extension # first we search the cache
180
- if search.results.empty? # when there are no cache hits
181
- search = Ray::GitHub.new extension # then search github
182
- else # when there are cache hits
183
- results = {}
184
- search.results.select do |name, info| # filter out non-git extensions
185
- info[:uri] =~ /github/
186
- end.map do |extension|
187
- results[extension.first] = extension.last # rebuild the results hash
188
- end
189
- if results.empty?
190
- search = Ray::GitHub.new extension
191
- else
192
- search.results = results # reset the results hash
193
- end
135
+ search = Ray::Search::RubyGems.new extension.to_extension_name
136
+ search.cache
137
+ if search.results.size == 1
138
+ extension = search.results.first.last
139
+ else
140
+ extension = search.multiple_choice
194
141
  end
195
- if search.results.size == 1 # when there is just one match
196
- extension = Ray::Zip.new search.results.first.last # that's our extension
197
- else # when there is more than one match
198
- extension = Ray::Zip.new search.multiple_choice # make the user pick
199
- end
200
- extension.uri += "/zipball/master" # github uses awkward naming
201
- extension.install # install the extension
202
- say "#{extension.name} => Installed!", :green
142
+ rubygem = Ray::Extension::RubyGem.new extension[:name], extension[:repository]
143
+ say "#{extension[:name]} => Bundling...", :yellow
144
+ rubygem.bundle
145
+ say "#{extension[:name]} => Running tasks...", :yellow
146
+ rubygem.install
147
+ say "#{extension[:name]} => Installation complete.", :green
203
148
  end
204
149
  else
205
- extension = Ray::Zip.new({ # instantiate with minimal info
206
- :name => extensions.first, # nothing works without a name
207
- :uri => options["zip"] # uri should be a zip archive
208
- })
209
- extension.install # install the extension
210
- say "#{extension.name} => Installed!", :green
150
+ # not sure what to do here, probably nothing
211
151
  end
212
152
  else
213
- p options
214
- end
215
- end
216
-
217
- desc "cache", "Inspect and clear the cache"
218
- method_option :clear, :desc => "Clear local cache", :type => :boolean
219
- def cache
220
- if options["clear"]
221
- Ray::Cache.clear
222
- else
223
- say File.read Ray::CACHE
153
+ extensions.each do |extension|
154
+ search = Ray::Search.new extension.to_extension_name
155
+ search.cache
156
+ if search.results.size == 1
157
+ extension = search.results.first.last
158
+ else
159
+ extension = search.multiple_choice
160
+ end
161
+ if extension[:version] == "latest"
162
+ git = Ray::Extension::Git.new extension[:name], extension[:repository]
163
+ say "#{extension[:name]} => Cloning...", :yellow
164
+ git.clone
165
+ say "#{extension[:name]} => Running tasks...", :yellow
166
+ git.install
167
+ say "#{extension[:name]} => Installation complete.", :green
168
+ else
169
+ rubygem = Ray::Extension::RubyGem.new extension[:name], extension[:repository]
170
+ say "#{extension[:name]} => Bundling...", :yellow
171
+ rubygem.bundle
172
+ say "#{extension[:name]} => Running tasks...", :yellow
173
+ rubygem.install
174
+ say "#{extension[:name]} => Installation complete.", :green
175
+ end
176
+ end
224
177
  end
225
178
  end
226
179
 
227
- desc "disable [EXTENSIONS]", "Disable extensions"
180
+ desc "disable [EXTENSION]", "Disable extensions"
228
181
  def disable *extensions
229
182
  extensions.each do |x|
230
183
  extension = x.to_extension_name
231
- if File.exist? "#{Ray::EXT_DIR}/#{extension}"
232
- Ray::Git.new({ :name => extension }).disable
184
+ if File.exist? "#{EXT_DIR}/#{extension}"
185
+ Ray::Extension.new(extension).disable
233
186
  say "#{extension} => Disabled.", :green
234
187
  elsif `bundle exec gem list`.include? "radiant-#{extension}-extension"
235
- Ray::Gem.new({ :name => extension }).disable
188
+ Ray::Extension::RubyGem.new(extension).disable
236
189
  say "#{extension} => Disabled.", :green
237
190
  end
238
191
  end
239
192
  end
240
193
 
241
- desc "enable [EXTENSIONS]", "Enable extensions"
194
+ desc "enable [EXTENSION]", "Enable extensions"
242
195
  def enable *extensions
243
196
  extensions.each do |x|
244
197
  extension = x.to_extension_name
245
- if File.exist? "#{Ray::EXT_DIR}/.disabled/#{extension}"
246
- Ray::Git.new({ :name => extension }).enable
198
+ if File.exist? "#{EXT_DIR}/.disabled/#{extension}"
199
+ Ray::Extension.new(extension).enable
247
200
  say "#{extension} => Enabled.", :green
248
201
  elsif `gem list`.include? "radiant-#{extension}-extension"
249
- Ray::Gem.new({ :name => extension }).enable
202
+ Ray::Extension::RubyGem.new(extension).enable
250
203
  say "#{extension} => Enabled.", :green
251
204
  end
252
205
  end
253
206
  end
254
207
 
255
- desc "uninstall [EXTENSIONS]", "Uninstall extensions"
208
+ desc "uninstall [EXTENSION]", "Uninstall extensions"
256
209
  def uninstall *extensions
257
210
  extensions.each do |x|
258
211
  extension = x.to_extension_name
259
- if File.exist? "#{Ray::EXT_DIR}/#{extension}"
260
- Ray::Git.new({ :name => extension }).uninstall
212
+ if File.exist? "#{EXT_DIR}/#{extension}"
213
+ Ray::Extension.new(extension).uninstall
261
214
  say "#{extension} => Uninstalled.", :green
262
215
  elsif `bundle exec gem list`.include? "radiant-#{extension}-extension"
263
- Ray::Gem.new({ :name => extension }).uninstall
216
+ Ray::Extension::RubyGem.new(extension).uninstall
264
217
  say "#{extension} => Uninstalled.", :green
265
218
  end
266
219
  end
data/lib/ray/constants.rb CHANGED
@@ -1,17 +1,12 @@
1
1
  # Friendly extension management for Radiant CMS
2
2
  module Ray
3
3
 
4
- VERSION = "3.0.0.alpha"
5
-
6
- RAY = File.expand_path "~/.ray"
7
- CACHE = "#{RAY}/cache.yml"
8
-
9
- ROOT = File.expand_path Dir.pwd
10
- GEMFILE = "#{ROOT}/Gemfile"
11
- EXT_DIR = "#{ROOT}/vendor/extensions"
12
- TMP_DIR = "#{ROOT}/tmp/ray"
13
- RG_V1_API = "http://rubygems.org/api/v1"
14
- GH_V2_API = "http://github.com/api/v2/json"
15
- GH_V3_API = "https://api.github.com"
4
+ VERSION = "3.0.0.pre" # current version
5
+ RAY = File.expand_path "~/.ray" # global settings directory
6
+ TMP = File.expand_path "#{Dir.pwd}/tmp/ray" # tmp directory
7
+ ROOT = Dir.pwd # current directory usually Rails.root
8
+ CACHE = File.expand_path "#{RAY}/cache.yml" # global cache file
9
+ EXT_DIR = File.expand_path "#{Dir.pwd}/vendor/extensions" # install location for "classic" extensions
10
+ GEMFILE = File.expand_path "#{Dir.pwd}/Gemfile" # project Gemfile
16
11
 
17
12
  end