Class: MrMurano::UserBase

Inherits:
SolutionBase show all
Defined in:
lib/MrMurano/Solution-Users.rb

Overview

User Management common things

Direct Known Subclasses

Role, User

Instance Method Summary collapse

Methods inherited from SolutionBase

#docmp, #dodiff, #endPoint, #initialize, #locallist, #status, #syncdown, #synckey, #syncup, #toRemoteItem, #tolocalname

Methods included from Verbose

#debug, #verbose

Methods included from Http

#curldebug, #delete, #get, #http, #http_reset, #json_opts, #post, #postf, #put, #set_def_headers, #showHttpError, #token, #tryToPrettyJSON, #workit

Constructor Details

This class inherits a constructor from MrMurano::SolutionBase

Instance Method Details

#download(local, item) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/MrMurano/Solution-Users.rb', line 39

def download(local, item)
  # needs to append/merge with file
  # for now, we'll read, modify, write
  here = []
  if local.exist? then
    local.open('rb') {|io| here = YAML.load(io)}
    here = [] if here == false
  end
  here.delete_if do |i|
    Hash.transform_keys_to_symbols(i)[@itemkey] == item[@itemkey]
  end
  here << item.reject{|k,v| k==:synckey}
  local.open('wb') do |io|
    io.write here.map{|i| Hash.transform_keys_to_strings(i)}.to_yaml
  end
end

#fetch(id) ⇒ Object



16
17
18
# File 'lib/MrMurano/Solution-Users.rb', line 16

def fetch(id)
  get('/' + id.to_s)
end

#listObject



12
13
14
# File 'lib/MrMurano/Solution-Users.rb', line 12

def list()
  get()
end

#localitems(from) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/MrMurano/Solution-Users.rb', line 77

def localitems(from)
  from = Pathname.new(from) unless from.kind_of? Pathname
  if not from.exist? then
    say_warning "Skipping missing #{from.to_s}"
    return []
  end
  unless from.file? then
    say_warning "Cannot read from #{from.to_s}"
    return []
  end
  key = @itemkey.to_sym

  here = []
  from.open {|io| here = YAML.load(io) }
  here = [] if here == false

  here.map{|i| Hash.transform_keys_to_symbols(i)}
end

#remove(id) ⇒ Object



20
21
22
# File 'lib/MrMurano/Solution-Users.rb', line 20

def remove(id)
  delete('/' + id.to_s)
end

#removelocal(dest, item) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/MrMurano/Solution-Users.rb', line 56

def removelocal(dest, item)
  # needs to append/merge with file
  # for now, we'll read, modify, write
  here = []
  if local.exist? then
    local.open('rb') {|io| here = YAML.load(io)}
    here = [] if here == false
  end
  key = @itemkey.to_sym
  here.delete_if do |it|
    Hash.transform_keys_to_symbols(it)[key] == item[key]
  end
  local.open('wb') do|io|
    io.write here.map{|i| Hash.transform_keys_to_strings(i)}.to_yaml
  end
end

#tolocalpath(into, item) ⇒ Object



73
74
75
# File 'lib/MrMurano/Solution-Users.rb', line 73

def tolocalpath(into, item)
  into
end

#upload(local, remote) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/MrMurano/Solution-Users.rb', line 24

def upload(local, remote)
  # Roles cannot be modified, so must delete and post.
  delete('/' + remote[@itemkey]) do |request, http|
    response = http.request(request)
    case response
    when Net::HTTPSuccess
    when Net::HTTPNotFound
    else
      showHttpError(request, response)
    end
  end
  remote.reject!{|k,v| k==:synckey or k==:bundled}
  post('/', remote)
end