Class: Worochi
- Inherits:
-
Object
- Object
- Worochi
- 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
-
.agents ⇒ Array
readonly
List of Agent waiting for Worochi.push.
Class Method Summary collapse
-
.add(agent) ⇒ nil
Adds an exist Agent to the list of agents listening to Worochi.push requests.
-
.create(service, token, opts = {}) ⇒ Worochi::Agent
Creates a new Agent and adds it to the list of agents listening to Worochi.push requests.
-
.init ⇒ nil
Initialize configurations and logging.
-
.list(print = true) ⇒ String
List the active agents in a human-readable form.
-
.push(origin, opts = {}) ⇒ Boolean
Push list of files using the active agents in Worochi.agents.
-
.remove(agent) ⇒ nil
Remove a specific Agent from the list of agents listening to Worochi.push requests.
-
.remove_service(service = nil) ⇒ nil
Remove all agents belonging to a given service from the list.
-
.reset ⇒ nil
Removes all agents from the list.
-
.size ⇒ Integer
Number of active agents.
Class Attribute Details
Class Method Details
.add(agent) ⇒ 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
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 |
.init ⇒ nil
Initialize configurations and logging.
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.
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.
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
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.
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 |
.reset ⇒ nil
Removes all agents from the list.
100 101 102 |
# File 'lib/worochi.rb', line 100 def reset @agents.clear end |
.size ⇒ Integer
Returns number of active agents.
118 119 120 |
# File 'lib/worochi.rb', line 118 def size @agents.size end |