Class: Slackup

Inherits:
Object
  • Object
show all
Defined in:
lib/slackup.rb,
lib/slackup/version.rb

Direct Known Subclasses

Channels, Groups, Ims, Stars, Users

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.0.7"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, client) ⇒ Slackup

Returns a new instance of Slackup.



58
59
60
61
62
# File 'lib/slackup.rb', line 58

def initialize(name, client)
  @name = name
  @client = client
  FileUtils.mkdir_p(name)
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



56
57
58
# File 'lib/slackup.rb', line 56

def client
  @client
end

#nameObject (readonly) Also known as: dirname

Returns the value of attribute name.



56
57
58
# File 'lib/slackup.rb', line 56

def name
  @name
end

Class Method Details

.backup(team_token_pairs = team_token_pairs()) ⇒ Object



46
47
48
49
50
51
52
53
54
# File 'lib/slackup.rb', line 46

def self.backup(team_token_pairs = team_token_pairs())
  team_token_pairs.each do |name, token|
    fork do
      client = configure_client(token)
      new(name, client).execute
    end
  end
  p Process.waitall
end

.configure_client(token) ⇒ Object



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_rootObject



17
18
19
# File 'lib/slackup.rb', line 17

def self.run_root
  RUN_ROOT
end

.team_token_pairsObject



27
28
29
30
31
32
33
# File 'lib/slackup.rb', line 27

def self.team_token_pairs
  if team_token_pairs_file.readable?
    YAML.load(team_token_pairs_file.read)
  else
    fail Error, "No team token pairs file found. See README for instructions."
  end
end

.team_token_pairs_fileObject



23
24
25
# File 'lib/slackup.rb', line 23

def self.team_token_pairs_file
  Pathname.glob(run_root.join("slack_teams.{json,yml,yaml}")).first
end

Instance Method Details

#executeObject



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(name, client).write!
    Groups.new(name, client).write!
    Stars.new(name, client).write!
    user_client.write!
    Ims.new(name, client).write!
  end
end