lib/onebox/engine.rb in onebox-1.5.0 vs lib/onebox/engine.rb in onebox-1.5.1
- old
+ new
@@ -11,12 +11,33 @@
end
attr_reader :url
attr_reader :cache
attr_reader :timeout
+
+ DEFUALT = {}
+ def options
+ @options
+ end
+
+ def options=(opt)
+ return @options if opt.nil? #make sure options provided
+ if opt.instance_of? OpenStruct
+ @options = @options.merge(opt.to_h)
+ else
+ @options = @options.merge(opt)
+ end
+ @options
+ end
+
def initialize(link, cache = nil, timeout = nil)
+
+ @options = DEFUALT
+ class_name = self.class.name.split("::").last.to_s
+ self.options = Onebox.options[class_name] || {} #Set the engine options extracted from global options.
+
@url = link
@cache = cache || Onebox.options.cache
@timeout = timeout || Onebox.options.timeout
end
@@ -39,12 +60,13 @@
end
private
def record
- result = cache.fetch(url) { data }
- cache[url] = result if cache.respond_to?(:key?)
+ url_result = url
+ result = cache.fetch(url_result) { data }
+ cache[url_result] = result if cache.respond_to?(:key?)
result
end
# raises error if not defined in onebox engine
# in each onebox, uses either Nokogiri or StandardEmbed to get raw HTML from url
@@ -99,9 +121,10 @@
require_relative "engine/standard_embed"
require_relative "engine/html"
require_relative "engine/json"
require_relative "engine/amazon_onebox"
require_relative "engine/classic_google_maps_onebox"
+require_relative "engine/github_issue_onebox"
require_relative "engine/github_blob_onebox"
require_relative "engine/github_commit_onebox"
# broken
#require_relative "engine/github_gist_onebox"
require_relative "engine/github_pullrequest_onebox"