lib/embeddable.rb in embeddable-0.0.7 vs lib/embeddable.rb in embeddable-0.0.8

- old
+ new

@@ -29,11 +29,17 @@ brightcove: [ %r{^(\d+)$} ] } + included do + @embeddables = [] + end + module ClassMethods + attr_reader :embeddables + def embeddable(name, options = {}) source = options.fetch :from define_method "#{name}_type" do url = send(source) @@ -51,15 +57,25 @@ SERVICES.map do |service, patterns| patterns.map { |pattern| url[pattern, 1] } end.flatten.compact.first end + define_method "#{name}?" do + send("#{name}_id") ? true : false + end + SERVICES.each do |service, pattern| define_method "#{name}_on_#{service}?" do send("#{name}_type") == service end end + + define_method "#{name}_source" do + source + end + + @embeddables << name end end end