Skip to content

Commit

Permalink
Remove memoizable (deprecated)
Browse files Browse the repository at this point in the history
  • Loading branch information
atd committed Jan 23, 2012
1 parent a47555c commit f053e8e
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 21 deletions.
1 change: 0 additions & 1 deletion lib/linkser.rb
@@ -1,4 +1,3 @@
require 'active_support'
require 'linkser/version'

module Linkser
Expand Down
10 changes: 5 additions & 5 deletions lib/linkser/object.rb
Expand Up @@ -3,9 +3,8 @@

module Linkser
class Object
extend ActiveSupport::Memoizable

attr_reader :url, :last_url, :head

def initialize url, last_url, head, options={}
@url = url
@last_url = last_url
Expand All @@ -14,6 +13,10 @@ def initialize url, last_url, head, options={}
end

def body
@body ||= build_body
end

def build_body
uri = URI.parse last_url
if uri.scheme and (uri.scheme.eql? "http" or uri.scheme.eql? "https")
http = Net::HTTP.new uri.host, uri.port
Expand All @@ -32,9 +35,6 @@ def body
return response.body
end
end

memoize :body

end
end

Expand Down
46 changes: 32 additions & 14 deletions lib/linkser/objects/html.rb
Expand Up @@ -7,18 +7,44 @@ module Objects
class HTML < Linkser::Object

def title
@title ||= build_title
end

def description
@description ||= build_description
end

def images
@images ||= build_images
end

def nokogiri
@nokogiri ||= Nokogiri::HTML(body)
end

def ogp
@ogp ||= build_ogp
end

def resource
@resource ||= build_resource
end

protected

def build_title
ogp && ogp.title ||
(e = nokogiri.css('title')).first && e.text
end

def description
def build_description
ogp && ogp.description ||
(e = nokogiri.css('meta').find { |meta|
meta.get_attribute("name").eql? "description"
}) && e.get_attribute("content")
end

def images
def build_images
max_images = @options[:max_images] || 5
Array.new.tap do |images|
if ogp and ogp.image
Expand Down Expand Up @@ -52,11 +78,7 @@ def images
end
end

def nokogiri
Nokogiri::HTML(body)
end

def ogp
def build_ogp
ogp = OpenGraph::Object.new
nokogiri.css('meta').each do |m|
if m.attribute('property') && m.attribute('property').to_s.match(/^og:(.+)$/i)
Expand All @@ -66,14 +88,10 @@ def ogp
ogp = false if ogp.keys.empty? || !ogp.valid?
ogp
end

def resource
return Linkser::Resource.new ogp if ogp
return nil
end

memoize :nokogiri, :ogp,
:title, :description, :images, :resource
def build_resource
Linkser::Resource.new ogp if ogp
end

private

Expand Down
1 change: 0 additions & 1 deletion linkser.gemspec
Expand Up @@ -25,7 +25,6 @@ Gem::Specification.new do |s|
s.add_runtime_dependency('rmagick', '~> 2.13.1')
s.add_runtime_dependency('ruby-imagespec', "~> 0.2.0")
s.add_runtime_dependency('opengraph', "~> 0.0.4")
s.add_runtime_dependency('activesupport', "> 2.2.1")

# Development Gem dependencies
#
Expand Down

0 comments on commit f053e8e

Please sign in to comment.