From 046afc2fea3f3eae26751b687871d23f3e62a39f Mon Sep 17 00:00:00 2001 From: Matt Aimonetti Date: Sun, 28 Sep 2008 23:43:14 -0700 Subject: [PATCH] ready for a first release --- README | 12 ++++++++++++ Rakefile | 4 ++-- dm-gvideo-adapter.gemspec | 28 +++++++++++++++++++++++++++ lib/dm-gvideo-adapter.rb | 2 +- spec/dm-gvideo-adapter_spec.rb | 32 ++++++++++++++++++++----------- spec/spec_helper.rb | 35 ++++++++++++++++++++++++++++++++++ 6 files changed, 99 insertions(+), 14 deletions(-) create mode 100644 dm-gvideo-adapter.gemspec diff --git a/README b/README index d510458..6b2edfd 100644 --- a/README +++ b/README @@ -4,11 +4,23 @@ dm-gvideo-adapter # dependencies Gvideo: http://github.com/mattetti/gvideo +install the dependency: + + $ sudo gem install mattetti-gvideo + +install this adapter + + $ sudo gem install mattetti-dm-gvideo-adapter + + Usage: # URI: googlevideo://A005148908335059515423 # google video user id +(or you can set the user_id in your database.yml) + + Video.all # returns all the user's videos Video.get("-2838281997424715962") Video.first(:title => "The Illuminati - Secret societies") diff --git a/Rakefile b/Rakefile index 49c65d2..dbe4ce3 100644 --- a/Rakefile +++ b/Rakefile @@ -4,7 +4,7 @@ require 'rubygems/specification' require 'date' GEM = "dm-gvideo-adapter" -GEM_VERSION = "0.0.1" +GEM_VERSION = "1.0.0" AUTHOR = "Matt Aimonetti" EMAIL = "mattaimonetti@gmail.com" HOMEPAGE = "http://merbist.com" @@ -23,7 +23,7 @@ spec = Gem::Specification.new do |s| s.homepage = HOMEPAGE # Uncomment this to add a dependency - # s.add_dependency "foo" + # s.add_dependency "gvideo" s.require_path = 'lib' s.autorequire = GEM diff --git a/dm-gvideo-adapter.gemspec b/dm-gvideo-adapter.gemspec new file mode 100644 index 0000000..797b611 --- /dev/null +++ b/dm-gvideo-adapter.gemspec @@ -0,0 +1,28 @@ +Gem::Specification.new do |s| + s.name = %q{dm-gvideo-adapter} + s.version = "1.0.0" + + s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= + s.authors = ["Matt Aimonetti"] + s.autorequire = %q{dm-gvideo-adapter} + s.date = %q{2008-09-28} + s.description = %q{A gem that provides...} + s.email = %q{mattaimonetti@gmail.com} + s.extra_rdoc_files = ["README", "LICENSE", "TODO"] + s.files = ["LICENSE", "README", "Rakefile", "TODO", "lib/dm-gvideo-adapter.rb", "lib/gvideo_model.rb"] + s.has_rdoc = true + s.homepage = %q{http://merbist.com} + s.require_paths = ["lib"] + s.rubygems_version = %q{1.2.0} + s.summary = %q{A gem that provides...} + + if s.respond_to? :specification_version then + current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION + s.specification_version = 2 + + if current_version >= 3 then + else + end + else + end +end diff --git a/lib/dm-gvideo-adapter.rb b/lib/dm-gvideo-adapter.rb index d5a9f7a..ab2ddd3 100644 --- a/lib/dm-gvideo-adapter.rb +++ b/lib/dm-gvideo-adapter.rb @@ -55,7 +55,7 @@ def read(query, set, arr = true) end # This is the core logic that handles the difference between all/first - (results || []).each do |result| + results.each do |result| props = props_from_result(properties_with_indexes, result, repository) arr ? set.load(props) : (break set.load(props, query)) end diff --git a/spec/dm-gvideo-adapter_spec.rb b/spec/dm-gvideo-adapter_spec.rb index 88de7bb..3bcf4af 100644 --- a/spec/dm-gvideo-adapter_spec.rb +++ b/spec/dm-gvideo-adapter_spec.rb @@ -32,53 +32,63 @@ @videos.length.should == @gvideos.length end - it "should be able to retrieve itams using a title (string) condition" do - videos = @videos.all(:title => "Durex: The Garden") + it "should be able to retrieve items using a title (string) condition" do + videos = Video.all(:title => "Durex: The Garden") videos.length.should == 1 videos.first.title.should == "Durex: The Garden" end it "should be able to retrieve items using a title (regexp) condition" do - videos = @videos.all(:title.like => "The Garden") + videos = Video.all(:title.like => "The Garden") videos.length.should == 1 videos.first.title.should == "Durex: The Garden" end it "should be able to retrieve items using a duration (integer) condition (seconds)" do - videos = @videos.all(:duration => 12) + videos = Video.all(:duration => 12) videos.length.should == 2 end it "should be able to retrieve items using a duration condition :gte " do - videos = @videos.all(:duration.gte => 13) + videos = Video.all(:duration.gte => 13) videos.length.should < @gvideos.length end it "should be able to retrieve items using a duration condition :lte " do - videos = @videos.all(:duration.lte => 12) + videos = Video.all(:duration.lte => 12) videos.length.should < @gvideos.length (@videos.all(:duration.gte => 13).length + @videos.all(:duration.lte => 12).length).should == @gvideos.length end it "should be able to use 2 duration conditions" do - videos = @videos.all(:duration.lte => 12, :duration.gte => 12) + videos = Video.all(:duration.lte => 12, :duration.gte => 12) videos.length.should == @videos.all(:duration => 12).length end end describe "getting one resource" do - before(:all) do - @video = Video.first - end it "should have all the attributes of a video" do + video = Video.first methods = %W{docid title video_url duration duration_in_minutes thumbnail_url embed_player} methods.each do |meth| - @video.send(meth.to_sym).should_not be_nil + video.send(meth.to_sym).should_not be_nil end end + it "should be able to retrieve an item using a title (string) condition" do + video = Video.first(:title => "Durex: The Garden") + video.should be_an_instance_of(Video) + video.title.should == "Durex: The Garden" + end + + it "should be able to retrieve items using a title (regexp) condition" do + video = Video.first(:title.like => "The Garden") + video.should be_an_instance_of(Video) + video.title.should == "Durex: The Garden" + end + end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index e0dbc7b..ad8c9d6 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -19,5 +19,40 @@ class Video property :thumbnail_url, String property :embed_player, String + ## + # Simulates Array#first by returning the first entry (when + # there are no arguments), or transforms the collection's query + # by applying :limit => n when you supply an Integer. If you + # provide a conditions hash, or a Query object, the internal + # query is scoped and a new collection is returned + # + # @param [Integer, Hash[Symbol, Object], Query] args + # + # @return [DataMapper::Resource, DataMapper::Collection] The + # first resource in the entries of this collection, or + # a new collection whose query has been merged + # + # @api public + def first(*args) + + # # TODO: this shouldn't be a kicker if scoped_query() is called + # if loaded? + # if args.empty? + # return super + # elsif args.size == 1 && args.first.kind_of?(Integer) + # limit = args.shift + # return self.class.new(scoped_query(:limit => limit)) { |c| c.replace(super(limit)) } + # end + # end + # + # query = args.last.respond_to?(:merge) ? args.pop : {} + # query = scoped_query(query.merge(:limit => args.first || 1)) + # + # if args.any? + # query.repository.read_many(query) + # else + # query.repository.read_one(query) + # end + end end \ No newline at end of file