Sha256: 91a47195beec0eb8d00d76980eb638449f56f2fd199491d8c3c334b9238a79cb

Contents?: true

Size: 914 Bytes

Versions: 13

Compression:

Stored size: 914 Bytes

Contents

module Octopussy
  class Repo
    attr_accessor :username, :name
  
    def initialize(repo)
      if repo.is_a?(String)
        repo = repo.split("/")
        @name = repo.pop
        @username = repo.pop
      elsif repo.is_a?(Repo)
        @username = repo.username
        @name = repo.name
      elsif repo.is_a?(Hash)
        @name = repo[:repo] ||= repo[:name] 
        @username = repo[:username] ||= repo[:user] ||= repo[:owner]
      end
    end
  
    def slug
      "#{@username}/#{@name}"
    end
  
    def to_s
      self.slug
    end
  
    def url
      "http://github.com/#{slug}"
    end
  
    def user
      @username
    end
  
    def repo
      @name
    end
  
    def user=(val)
      @username = val
    end
  
    def self.from_url(url)
      return if url.nil?
      username, name = url.gsub("http://github.com/", "").split("/")
      Repo.new("#{username}/#{name}")
    end
  end
end

Version data entries

13 entries across 13 versions & 2 rubygems

Version Path
octopussy-0.3.1 lib/octopussy/repo.rb
opsb-octopussy-0.3.0 lib/octopussy/repo.rb
octopussy-0.3.0 lib/octopussy/repo.rb
octopussy-0.2.4 lib/octopussy/repo.rb
octopussy-0.2.3 lib/octopussy/repo.rb
octopussy-0.2.2 lib/octopussy/repo.rb
octopussy-0.2.1 lib/octopussy/repo.rb
octopussy-0.2.0 lib/octopussy/repo.rb
octopussy-0.1.4 lib/octopussy/repo.rb
octopussy-0.1.3 lib/octopussy/repo.rb
octopussy-0.1.2 lib/octopussy/repo.rb
octopussy-0.1.1 lib/octopussy/repo.rb
octopussy-0.1.0 lib/octopussy/repo.rb