Module: Murlsh
- Defined in:
- lib/murlsh/uri_domain.rb,
lib/murlsh/url.rb,
lib/murlsh/doc.rb,
lib/murlsh/ask.rb,
lib/murlsh/auth.rb,
lib/murlsh/markup.rb,
lib/murlsh/plugin.rb,
lib/murlsh/uri_ask.rb,
lib/murlsh/dispatch.rb,
lib/murlsh/time_ago.rb,
lib/murlsh/openlock.rb,
lib/murlsh/url_body.rb,
lib/murlsh/json_body.rb,
lib/murlsh/failproof.rb,
lib/murlsh/cp_r_safe.rb,
lib/murlsh/img_store.rb,
lib/murlsh/build_md5.rb,
lib/murlsh/image_list.rb,
lib/murlsh/jsonp_body.rb,
lib/murlsh/url_server.rb,
lib/murlsh/json_server.rb,
lib/murlsh/build_query.rb,
lib/murlsh/head_from_get.rb,
lib/murlsh/search_grammar.rb,
lib/murlsh/url_result_set.rb,
lib/murlsh/delicious_parse.rb,
lib/murlsh/must_revalidate.rb,
lib/murlsh/etag_add_encoding.rb,
lib/murlsh/search_conditions.rb,
lib/murlsh/yaml_ordered_hash.rb,
lib/murlsh/uri_get_path_query.rb,
lib/murlsh/far_future_expires.rb
Overview
URI mixin that adds method to get domain.
Defined Under Namespace
Modules: BuildMd5, Doc, HeadFromGet, ImageList, Markup, SearchGrammar, TimeAgo, URIDomain, URIGetPathQuery, UriAsk, YamlOrderedHash Classes: Auth, Dispatch, EtagAddEncoding, FarFutureExpires, ImgStore, JsonBody, JsonServer, JsonpBody, MustRevalidate, Plugin, SearchConditions, SearchGrammarParser, Url, UrlBody, UrlResultSet, UrlServer
Instance Method Summary (collapse)
-
- (Object) ask(prompt, default)
Ask the user a question and return the answer.
-
- (Object) build_query(h)
Query string builder.
-
- (Object) cp_r_safe(sources, dest, options)
Recursive copy from sources to destination but ask before overwriting.
-
- (Object) delicious_parse(source)
Parse a delicious xml export and yield a hash for each bookmark.
-
- (Object) failproof(options = {})
Catch all exceptions unless options = false.
-
- (Object) openlock(*args)
Open a file with an exclusive lock.
Instance Method Details
- (Object) ask(prompt, default)
Ask the user a question and return the answer.
6 7 8 9 10 11 |
# File 'lib/murlsh/ask.rb', line 6 def ask(prompt, default) print "#{prompt} [#{default}] " answer = $stdin.gets.strip answer = default if answer.empty? answer end |
- (Object) build_query(h)
Query string builder. Takes hash of query string variables.
6 7 8 |
# File 'lib/murlsh/build_query.rb', line 6 def build_query(h) h.empty? ? '' : '?' + h.map { |k,v| URI.escape "#{k}=#{v}" }.join('&') end |
- (Object) cp_r_safe(sources, dest, options)
Recursive copy from sources to destination but ask before overwriting.
Options are passed into FileUtils.mkdir_p FileUtils.copy.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/murlsh/cp_r_safe.rb', line 12 def cp_r_safe(sources, dest, ) sources.each do |source| new = File.join(dest, File.split(File.(source)).last) if File.directory?(source) FileUtils.mkdir_p(new, ) cp_r_safe(Dir.entries(source). reject { |f| %w{. ..}.include?(f) }. map { |f| File.join(source, f) }, new, ) else answer = if File.exists?(new) Murlsh.ask("#{new} exists. Overwrite?", 'n') else 'y' end FileUtils.copy(source, new, ) if answer == 'y' end end end |
- (Object) delicious_parse(source)
Parse a delicious xml export and yield a hash for each bookmark.
To export your delicious bookmarks:
curl https://user:password@api.del.icio.us/v1/posts/all > delicious.xml
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/murlsh/delicious_parse.rb', line 14 def delicious_parse(source) doc = Nokogiri::XML(open(source)) doc.xpath('//post').each do |p| result = {} p.each { |k,v| result[k.to_sym] = v } result[:tag] = result[:tag].split result[:time] = Time.parse(result[:time]) # extract via information from extended result[:via] = result[:extended].chomp(')')[%r{via\s+([^\s]+)}, 1] result[:via_url] = begin if result[:via] and %w{http https}.include?(URI(result[:via]).scheme.to_s.downcase) result[:via] end rescue URI::InvalidURIError end yield result end end |
- (Object) failproof(options = {})
Catch all exceptions unless options = false.
6 7 8 9 10 11 12 |
# File 'lib/murlsh/failproof.rb', line 6 def failproof(={}) begin yield rescue Exception raise unless .fetch(:failproof, true) end end |
- (Object) openlock(*args)
Open a file with an exclusive lock.
6 7 8 9 10 |
# File 'lib/murlsh/openlock.rb', line 6 def openlock(*args) open(*args) do |f| f.flock(File::LOCK_EX) ; yield f ; f.flock(File::LOCK_UN) end end |