Class: Worochi

Inherits:
Object
  • Object
show all
Defined in:
lib/worochi.rb,
lib/worochi/log.rb,
lib/worochi/item.rb,
lib/worochi/agent.rb,
lib/worochi/oauth.rb,
lib/worochi/config.rb,
lib/worochi/helper.rb,
lib/worochi/version.rb,
lib/worochi/agent/box.rb,
lib/worochi/agent/github.rb,
lib/worochi/configurator.rb,
lib/worochi/agent/dropbox.rb,
lib/worochi/agent/#example.rb,
lib/worochi/agent/google_drive.rb,
lib/worochi/helper/github_helper.rb

Overview

The main class for the gem. This and the Agent class are the main endpoints for interacting with the remote services.

Defined Under Namespace

Modules: Config, Helper Classes: Agent, Error, Item, Log, OAuth

Constant Summary collapse

VERSION =

Current version of the gem

'0.0.18'

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.agentsArray (readonly)

List of Agent waiting for push.

Returns:

  • (Array)


22
23
24
# File 'lib/worochi.rb', line 22

def agents
  @agents
end

Class Method Details

.add(agent) ⇒ nil

Adds an exist Agent to the list of agents listening to push requests.

Parameters:

Returns:

  • (nil)


65
66
67
68
# File 'lib/worochi.rb', line 65

def add(agent)
  @agents << agent unless @agents.include?(agent)
  nil
end

.create(service, token, opts = {}) ⇒ Worochi::Agent

Creates a new Agent and adds it to the list of agents listening to push requests.

Examples:

Worochi.create(:dropbox, 'as89h38nFBUSHFfuh99f', { dir: '/folder' })
opts = {
  repo: 'darkmirage/worochi',
  source: 'master',
  target: 'temp',
  commit_msg: 'Hello'
}
Worochi.create(:github, '6st46setsytgbhd64', opts)

Parameters:

  • service (Symbol)

    service name as defined in Worochi::Config.services

  • token (String)

    authorization token for the service API

  • opts (Hash) (defaults to: {})

    additional service-specific options

Returns:

See Also:



51
52
53
54
55
56
57
58
# File 'lib/worochi.rb', line 51

def create(service, token, opts={})
  opts ||= {}
  opts[:service] = service.to_sym
  opts[:token] = token
  agent = Agent.new(opts)
  @agents << agent
  agent
end

.initnil

Initialize configurations and logging.

Returns:

  • (nil)


27
28
29
30
31
# File 'lib/worochi.rb', line 27

def init
  Config.load_yaml
  Log.init
  reset
end

.list(print = true) ⇒ String

List the active agents in a human-readable form.

Parameters:

  • print (Boolean) (defaults to: true)

    prints the result if ‘true`

Returns:

  • (String)

    formatted list of agents



108
109
110
111
112
113
114
115
# File 'lib/worochi.rb', line 108

def list(print=true)
  list = @agents.each_with_index.map do |a, i|
    "  \033[33m# #{i}\033[0m\t#{a.name}"
  end
  result = list.join("\n")
  puts result if print && !result.empty?
  result
end

.push(origin, opts = {}) ⇒ Boolean

Push list of files using the active agents in agents. Refer to Worochi::Item.open for how to format the file list.

Parameters:

  • origin (Array<Hash>, Array<String>, Hash, String)
  • opts (Hash) (defaults to: {})

    update agent options before pushing

Returns:

  • (Boolean)

    success

See Also:



130
131
132
133
134
135
136
137
138
# File 'lib/worochi.rb', line 130

def push(origin, opts={})
  opts ||= {}
  if @agents.empty?
    Log.warn 'No push targets specified'
    return false
  end
  @agents.each { |agent| agent.push(origin, opts) }
  true
end

.remove(agent) ⇒ nil

Remove a specific Agent from the list of agents listening to push requests.

Parameters:

Returns:

  • (nil)


75
76
77
78
# File 'lib/worochi.rb', line 75

def remove(agent)
  @agents.delete(agent)
  nil
end

.remove_service(service = nil) ⇒ nil

Remove all agents belonging to a given service from the list. Removes all agents if service is not specified.

Examples:

Worochi.remove(:dropbox)

Parameters:

Returns:

  • (nil)

See Also:



88
89
90
91
92
93
94
95
# File 'lib/worochi.rb', line 88

def remove_service(service=nil)
  if service.nil?
    reset
  else
    @agents.reject! { |a| a.type == service }
  end
  nil
end

.resetnil

Removes all agents from the list.

Returns:

  • (nil)


100
101
102
# File 'lib/worochi.rb', line 100

def reset
  @agents.clear
end

.sizeInteger

Returns number of active agents.

Returns:

  • (Integer)

    number of active agents.



118
119
120
# File 'lib/worochi.rb', line 118

def size
  @agents.size
end