Module: Arisaid::Syncable

Included in:
Bots, Guests, Usergroups, Users
Defined in:
lib/arisaid/syncable.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#local_fileObject



5
6
7
8
9
# File 'lib/arisaid/syncable.rb', line 5

def local_file
  name = self.class.name.split('::').last.downcase
  @local_file ||=
    "#{Arisaid.conf_prefix if Arisaid.conf_prefix}#{name}.yml"
end

Instance Method Details

#applyObject



58
59
# File 'lib/arisaid/syncable.rb', line 58

def apply
end

#initialize(team = nil) ⇒ Object



50
51
52
# File 'lib/arisaid/syncable.rb', line 50

def initialize(team = nil)
  Arisaid.slack_team = team if team
end

#localObject



22
23
24
# File 'lib/arisaid/syncable.rb', line 22

def local
  merge_users(local_by_stdin || local_by_file)
end

#local_by_fileObject



36
37
38
39
40
41
# File 'lib/arisaid/syncable.rb', line 36

def local_by_file
  unless File.exists?(local_file_path)
    raise Arisaid::ConfNotFound.new("Not found: #{local_file_path}")
  end
  YAML.load_file(local_file_path)
end

#local_by_stdinObject



26
27
28
29
30
31
32
33
34
# File 'lib/arisaid/syncable.rb', line 26

def local_by_stdin
  if File.pipe?(STDIN) || File.select([STDIN], [], [], 0) != nil
    buffer = ''
    while str = STDIN.gets
      buffer << str
    end
    YAML.load(buffer.chomp)
  end
end

#local_file_pathObject



11
12
13
# File 'lib/arisaid/syncable.rb', line 11

def local_file_path
  File.join(Dir.pwd, local_file)
end

#merge_users(config) ⇒ Object



43
44
45
46
47
48
# File 'lib/arisaid/syncable.rb', line 43

def merge_users(config)
  config.map do |c|
    c["users"] = c["users"].flatten.uniq
    c
  end
end

#remoteObject



15
16
17
# File 'lib/arisaid/syncable.rb', line 15

def remote
  @remote || remote!
end

#remote!Object



19
20
# File 'lib/arisaid/syncable.rb', line 19

def remote!
end

#same?(src, dst) ⇒ Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/arisaid/syncable.rb', line 61

def same?(src, dst)
  src == dst
end

#saveObject



65
66
67
# File 'lib/arisaid/syncable.rb', line 65

def save
  File.write local_file_path, remote.to_yaml
end

#showObject



54
55
56
# File 'lib/arisaid/syncable.rb', line 54

def show
  puts remote.to_yaml
end