diff --git a/lib/octopi/tree.rb b/lib/octopi/tree.rb new file mode 100644 index 0000000..6cb5f28 --- /dev/null +++ b/lib/octopi/tree.rb @@ -0,0 +1,15 @@ +module Octopi + class Tree < Base + attr_accessor :name, :size, :sha, :mode, :mime_type, :type, :user, :repository + + def self.find(options) + ensure_hash(options) + user, repo = gather_details(options) + route = "/tree/show/#{user}/#{repo}/#{options[:sha]}" + trees = Api.api.get(route)["tree"].map do |tree| + Tree.new(tree.merge(:user => user, :repository => repo)) + end + TreeSet.new(trees) + end + end +end \ No newline at end of file diff --git a/lib/octopi/tree_set.rb b/lib/octopi/tree_set.rb new file mode 100644 index 0000000..6ff9afd --- /dev/null +++ b/lib/octopi/tree_set.rb @@ -0,0 +1,11 @@ +require File.join(File.dirname(__FILE__), "tree") +class Octopi::TreeSet < Array + include Octopi + attr_accessor :user, :repository + + def initialize(array) + self.user = array.first.user + self.repository = array.first.repository + super(array) + end +end \ No newline at end of file diff --git a/test/tree_test.rb b/test/tree_test.rb new file mode 100644 index 0000000..a5fa740 --- /dev/null +++ b/test/tree_test.rb @@ -0,0 +1,15 @@ +require File.expand_path(File.join(File.dirname(__FILE__), 'test_helper')) + +class TreeTest < Test::Unit::TestCase + include Octopi + + def setup + fake_everything + end + + should "be able to find a tree set" do + shared_options = { :user => "fcoury", :repo => "octopi"} + branch = Branch.all(shared_options).detect { |b| b.name == "master" } + assert Tree.find(shared_options.merge!(:sha => branch.sha)).is_a?(TreeSet) + end +end