Class: Worochi::Agent
- Inherits:
-
Object
- Object
- Worochi::Agent
- Defined in:
- lib/worochi/agent.rb
Overview
The parent class for all service agents.
Direct Known Subclasses
Defined Under Namespace
Classes: Box, Dropbox, Example, Github, GoogleDrive
Instance Attribute Summary collapse
-
#options ⇒ Hashie::Mash
Service options.
Class Method Summary collapse
-
.new(opts = {}) ⇒ Agent
Creates a new service-specific Agent based on
:service.
Instance Method Summary collapse
-
#files(*args) ⇒ Array<String>, Array<Hash>
Returns a list of files at the remote path specified by
options[:dir]. -
#files_and_folders(*args) ⇒ Array<String>, Array<Hash>
Returns a list of files and folders at the remote path specified by
options[:dir]. -
#folders(*args) ⇒ Array<String>, Array<Hash>
Returns a list of subdirectories at the remote path specified by
options[:dir]. -
#initialize(opts = {}) ⇒ Agent
constructor
A new instance of Agent.
-
#name ⇒ String
Returns the display name for the agent’s service.
-
#push(origin, opts = nil) ⇒ nil
Push list of files to the service.
-
#push_items(items) ⇒ nil
Push a list of Item to the service.
-
#remove ⇒ nil
Remove the agent from the list of active agents responding to calls to push.
-
#set_dir(path) ⇒ Hashie::Mash
Sets the remote target directory path.
-
#set_options(opts = {}) ⇒ Hashie::Mash
Updates #options using
opts. -
#type ⇒ Symbol
Returns the service type for the agent.
Constructor Details
#initialize(opts = {}) ⇒ Agent
Returns a new instance of Agent.
11 12 13 14 |
# File 'lib/worochi/agent.rb', line 11 def initialize(opts={}) (opts) init_client end |
Instance Attribute Details
#options ⇒ Hashie::Mash
Service options.
8 9 10 |
# File 'lib/worochi/agent.rb', line 8 def end |
Class Method Details
.new(opts = {}) ⇒ Agent
Creates a new service-specific Worochi::Agent based on :service.
223 224 225 226 227 228 229 230 231 |
# File 'lib/worochi/agent.rb', line 223 def new(opts={}) service = opts[:service] if self.name == 'Worochi::Agent' raise Error, 'Invalid service' unless Config.services.include?(service) Agent.const_get(class_name(service)).new(opts) else super end end |
Instance Method Details
#files(details) ⇒ Array<String>, Array<Hash> #files(path, details = false) ⇒ Array<String>, Array<Hash>
Returns a list of files at the remote path specified by options[:dir]. Relies on the service-specific implementation of #list.
76 77 78 |
# File 'lib/worochi/agent.rb', line 76 def files(*args) list_helper(:files, args) end |
#files_and_folders(*args) ⇒ Array<String>, Array<Hash>
Returns a list of files and folders at the remote path specified by options[:dir]. Relies on the service-specific implementation of #list. Refer to #files for overloaded prototypes.
98 99 100 |
# File 'lib/worochi/agent.rb', line 98 def files_and_folders(*args) list_helper(:both, args) end |
#folders(*args) ⇒ Array<String>, Array<Hash>
Returns a list of subdirectories at the remote path specified by options[:dir]. Relies on the service-specific implementation of #list. Refer to #files for overloaded prototypes.
89 90 91 |
# File 'lib/worochi/agent.rb', line 89 def folders(*args) list_helper(:folders, args) end |
#name ⇒ String
Returns the display name for the agent’s service.
132 133 134 |
# File 'lib/worochi/agent.rb', line 132 def name Worochi::Config.service_display_name(.service) end |
#push(origin, opts = nil) ⇒ nil
Push list of files to the service. Refer to Item.open for how to format the file list. An optional opts hash can be used to update the agent options before pushing.
27 28 29 30 31 32 |
# File 'lib/worochi/agent.rb', line 27 def push(origin, opts=nil) (opts) unless opts.nil? items = Item.open(origin) push_items(items) nil end |
#push_items(items) ⇒ nil
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/worochi/agent.rb', line 38 def push_items(items) items.each { |item| item.content.rewind } Worochi::Log.info "Pushing #{items.size} items to #{type}" if respond_to?(:push_all) push_all(items) else items.each { |item| push_item(item) } end Worochi::Log.info "Push to #{type} completed" nil end |
#remove ⇒ nil
Remove the agent from the list of active agents responding to calls to Worochi.push.
54 55 56 57 |
# File 'lib/worochi/agent.rb', line 54 def remove Worochi.remove(self) nil end |
#set_dir(path) ⇒ Hashie::Mash
Sets the remote target directory path. This is the same as modifying options[:dir].
117 118 119 120 |
# File 'lib/worochi/agent.rb', line 117 def set_dir(path) .dir = path end |
#set_options(opts = {}) ⇒ Hashie::Mash
Updates #options using opts.
106 107 108 109 110 |
# File 'lib/worochi/agent.rb', line 106 def (opts={}) self. ||= opts = Hashie::Mash.new(opts) .merge!(opts) end |
#type ⇒ Symbol
Returns the service type for the agent.
125 126 127 |
# File 'lib/worochi/agent.rb', line 125 def type .service end |