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.0"
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(name, client) ⇒ Slackup
Returns a new instance of Slackup.
60
61
62
63
64
|
# File 'lib/slackup.rb', line 60
def initialize(name, client)
@name = name
@client = client
FileUtils.mkdir_p(name)
end
|
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
58
59
60
|
# File 'lib/slackup.rb', line 58
def client
@client
end
|
#name ⇒ Object
Also known as:
dirname
Returns the value of attribute name.
58
59
60
|
# File 'lib/slackup.rb', line 58
def name
@name
end
|
Class Method Details
.backup(team_config = team_config()) ⇒ Object
46
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/slackup.rb', line 46
def self.backup(team_config = team_config())
team_config.each do |config|
fork do
name = config.fetch("nickname") { config.fetch("name") }
token = config.fetch("token")
client = configure_client(token)
new(name, client).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
#execute ⇒ Object
66
67
68
|
# File 'lib/slackup.rb', line 66
def execute
authorize! && write!
end
|
#write! ⇒ Object
70
71
72
73
74
75
76
77
78
|
# File 'lib/slackup.rb', line 70
def write!
Dir.chdir(dirname) do
Channels.new(name, client).write!
Groups.new(name, client).write!
Stars.new(name, client).write!
user_client.write!
Ims.new(name, client).write!
end
end
|