Module: Murlsh
- Defined in:
- lib/murlsh/uri_domain.rb,
lib/murlsh/doc.rb,
lib/murlsh/url.rb,
lib/murlsh/auth.rb,
lib/murlsh/markup.rb,
lib/murlsh/plugin.rb,
lib/murlsh/uri_ask.rb,
lib/murlsh/dispatch.rb,
lib/murlsh/openlock.rb,
lib/murlsh/time_ago.rb,
lib/murlsh/url_body.rb,
lib/murlsh/failproof.rb,
lib/murlsh/img_store.rb,
lib/murlsh/image_list.rb,
lib/murlsh/url_server.rb,
lib/murlsh/build_query.rb,
lib/murlsh/config_server.rb,
lib/murlsh/head_from_get.rb,
lib/murlsh/delicious_parse.rb,
lib/murlsh/must_revalidate.rb,
lib/murlsh/etag_add_encoding.rb,
lib/murlsh/yaml_ordered_hash.rb,
lib/murlsh/far_future_expires.rb,
lib/murlsh/uri_get_path_query.rb
Overview
URI mixin that adds method to get domain.
Defined Under Namespace
Modules: Doc, HeadFromGet, ImageList, Markup, TimeAgo, URIDomain, URIGetPathQuery, UriAsk, YamlOrderedHash Classes: Auth, ConfigServer, Dispatch, EtagAddEncoding, FarFutureExpires, ImgStore, MustRevalidate, Plugin, Url, UrlBody, UrlServer
Class Method Summary collapse
-
.build_query(h) ⇒ Object
Query string builder.
-
.delicious_parse(source) ⇒ Object
Parse a delicious xml export and yield a hash for each bookmark.
-
.failproof(options = {}) ⇒ Object
Catch all exceptions unless options = false.
-
.openlock(*args) ⇒ Object
Open a file with an exclusive lock.
Class Method Details
.build_query(h) ⇒ Object
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 |
.delicious_parse(source) ⇒ Object
Parse a delicious xml export and yield a hash for each bookmark.
To export your delicious bookmarks:
curl https://user:[email protected]/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 |
.failproof(options = {}) ⇒ Object
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 |
.openlock(*args) ⇒ Object
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 |