Class: Datagraph::Account

Inherits:
Resource show all
Defined in:
lib/datagraph/account.rb

Overview

Represents a Datagraph.org user account.

Constant Summary

SPEC =

/account

%r(^([^/]+)$)

Constants inherited from Resource

HEADERS

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods inherited from Resource

#<=>, #eql?, #exists?, #get, #head, #inspect, #inspect!, new, #to_rdf, #to_uri

Constructor Details

- (Account) initialize(name)

A new instance of Account

Parameters:

  • (String, #to_s) name


34
35
36
37
# File 'lib/datagraph/account.rb', line 34

def initialize(name)
  @name = name.to_s
  super(Datagraph::URL.join(@name))
end

Instance Attribute Details

- (String) name (readonly)

Returns:

  • (String)


30
31
32
# File 'lib/datagraph/account.rb', line 30

def name
  @name
end

Class Method Details

+ (Boolean) exists?(name)

Returns true if an account with the given name exists on Datagraph.org.

Parameters:

  • (String, #to_s) name

Returns:

  • (Boolean)


13
14
15
# File 'lib/datagraph/account.rb', line 13

def self.exists?(name)
  Account.new(name).exists?
end

+ (Account) register!(name, options = {})

Registers a new user account with Datagraph.org.

Parameters:

  • (String) name
  • (Hash{Symbol => Object}) options (defaults to: {})

Options Hash (options):

  • (String) :password N/A

Returns:



24
25
26
27
# File 'lib/datagraph/account.rb', line 24

def self.register!(name, options = {})
  Datagraph::Client.rpc.call('datagraph.account.register', name, options[:password])
  self.new(name)
end

Instance Method Details

- (Array<Repository>) repositories

Returns the list of repositories belonging to this account.

Returns:



52
53
54
55
56
# File 'lib/datagraph/account.rb', line 52

def repositories
  Repository.each(:account_name => name).select do |repository|
    repository..name == name
  end
end

- (Repository) repository(name)

Returns the given repository belonging to this account.

Parameters:

  • (String, #to_s) name

Returns:



44
45
46
# File 'lib/datagraph/account.rb', line 44

def repository(name)
  Repository.new(self, name)
end

- (String) to_s

Returns a string representation of the account name.

Returns:

  • (String)


62
63
64
# File 'lib/datagraph/account.rb', line 62

def to_s
  name
end