Class: Slackup
- Inherits:
-
Object
show all
- Defined in:
- lib/slackup.rb,
lib/slackup/version.rb
Defined Under Namespace
Classes: Channels, Groups, Ims, Stars, Users
Constant Summary
collapse
- Error =
Class.new(StandardError)
- RUN_ROOT =
Pathname Dir.pwd
- SEMAPHORE =
Mutex.new
- VERSION =
"0.1.1"
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(config, client = nil) ⇒ Slackup
Returns a new instance of Slackup.
57
58
59
60
61
62
|
# File 'lib/slackup.rb', line 57
def initialize(config, client=nil)
@config = config
@name = config.fetch("nickname") { config.fetch("name") }
@client = client || configure_client
FileUtils.mkdir_p(name)
end
|
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
55
56
57
|
# File 'lib/slackup.rb', line 55
def client
@client
end
|
#name ⇒ Object
Also known as:
dirname
Returns the value of attribute name.
55
56
57
|
# File 'lib/slackup.rb', line 55
def name
@name
end
|
Class Method Details
.backup(team_config = team_config()) ⇒ Object
46
47
48
49
50
51
52
53
|
# File 'lib/slackup.rb', line 46
def self.backup(team_config = team_config())
team_config.each do |config|
fork do
new(config).execute
end
end
p Process.waitall
end
|
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/slackup.rb', line 35
def self.configure_client(token)
client = nil
SEMAPHORE.synchronize do
Slack.configure do |config|
config.token = token
end
client = Slack.client
end
client
end
|
.run_root ⇒ Object
17
18
19
|
# File 'lib/slackup.rb', line 17
def self.run_root
RUN_ROOT
end
|
.team_config ⇒ Object
27
28
29
30
31
32
33
|
# File 'lib/slackup.rb', line 27
def self.team_config
if team_config_file.readable?
YAML.load(team_config_file.read)
else
fail Error, "No team config file found. See README for instructions."
end
end
|
.team_config_file ⇒ Object
23
24
25
|
# File 'lib/slackup.rb', line 23
def self.team_config_file
Pathname.glob(run_root.join("slack_teams.{json,yml,yaml}")).first
end
|
Instance Method Details
78
79
80
81
|
# File 'lib/slackup.rb', line 78
def configure_client
token = config.fetch("token")
self.class.configure_client(token)
end
|
#execute ⇒ Object
64
65
66
|
# File 'lib/slackup.rb', line 64
def execute
authorize! && write!
end
|
#write! ⇒ Object
68
69
70
71
72
73
74
75
76
|
# File 'lib/slackup.rb', line 68
def write!
Dir.chdir(dirname) do
Channels.new(config, client).write!
Groups.new(config, client).write!
Stars.new(config, client).write!
user_client.write!
Ims.new(config, client).write!
end
end
|