Module: Arisaid::Syncable
- Included in:
- Bots, Guests, Usergroups, Users
- Defined in:
- lib/arisaid/syncable.rb
Instance Attribute Summary collapse
Instance Method Summary collapse
- #apply ⇒ Object
- #initialize(team = nil) ⇒ Object
- #local ⇒ Object
- #local_by_file ⇒ Object
- #local_by_stdin ⇒ Object
- #local_file_path ⇒ Object
- #merge_users(config) ⇒ Object
- #remote ⇒ Object
- #remote! ⇒ Object
- #same?(src, dst) ⇒ Boolean
- #save ⇒ Object
- #show ⇒ Object
Instance Attribute Details
Instance Method Details
#apply ⇒ Object
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 |
#local ⇒ Object
22 23 24 |
# File 'lib/arisaid/syncable.rb', line 22 def local merge_users(local_by_stdin || local_by_file) end |
#local_by_file ⇒ Object
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_stdin ⇒ Object
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_path ⇒ Object
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 |
#remote ⇒ Object
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
61 62 63 |
# File 'lib/arisaid/syncable.rb', line 61 def same?(src, dst) src == dst end |
#save ⇒ Object
65 66 67 |
# File 'lib/arisaid/syncable.rb', line 65 def save File.write local_file_path, remote.to_yaml end |
#show ⇒ Object
54 55 56 |
# File 'lib/arisaid/syncable.rb', line 54 def show puts remote.to_yaml end |