Class: MrMurano::Cors

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

Instance Method Summary collapse

Methods inherited from SolutionBase

#endPoint

Methods included from SyncUpDown

#dodiff, #download, #ignoring, #locallist, #searchFor, #status, #syncdown, #synckey, #syncup, #toRemoteItem, #tolocalname

Methods included from Verbose

#debug, #error, #outf, #tabularize, #verbose, #warning

Methods included from Http

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

Constructor Details

#initializeCors

Returns a new instance of Cors.



7
8
9
10
11
# File 'lib/MrMurano/Solution-Cors.rb', line 7

def initialize
  super
  @uriparts << 'cors'
  @location = $cfg['location.cors']
end

Instance Method Details

#docmp(itemA, itemB) ⇒ Object

True if itemA and itemB are different



78
79
80
# File 'lib/MrMurano/Solution-Cors.rb', line 78

def docmp(itemA, itemB)
  itemA != itemB
end

#fetch(id = nil, &block) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/MrMurano/Solution-Cors.rb', line 19

def fetch(id=nil, &block)
  ret = get()
  if ret.kind_of?(Hash) and ret.has_key?(:cors) then
    # XXX cors is a JSON encoded string. That seems weird. keep an eye on this.
    data = JSON.parse(ret[:cors], @json_opts)
  else
    data = ret
  end
  if block_given? then
    yield Hash.transform_keys_to_strings(data).to_yaml
  else
    data
  end
end

#listObject



13
14
15
16
17
# File 'lib/MrMurano/Solution-Cors.rb', line 13

def list()
  data = fetch()
  data[:id] = 'cors'
  [data]
end

#localitems(from) ⇒ Object



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

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

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

  here[:id] = 'cors'
  here[:local_path] = from
  [ Hash.transform_keys_to_symbols(here) ]
end

#remove(id) ⇒ Object



34
35
36
# File 'lib/MrMurano/Solution-Cors.rb', line 34

def remove(id)
  # Not really anything to do here. Return to defaults? maybe?
end

#removelocal(dest, item) ⇒ Object



52
53
54
# File 'lib/MrMurano/Solution-Cors.rb', line 52

def removelocal(dest, item)
  # this is a nop.
end

#tolocalpath(into, item) ⇒ Object



48
49
50
# File 'lib/MrMurano/Solution-Cors.rb', line 48

def tolocalpath(into, item)
  into
end

#upload(local, remote, modify = false) ⇒ Object

Upload CORS :local path to file to push :remote hash of method and endpoint path (ignored for now)

Parameters:

  • modify (defaults to: false)

    Bool: True if item exists already and this is changing it



43
44
45
46
# File 'lib/MrMurano/Solution-Cors.rb', line 43

def upload(local, remote, modify=false)
  remote.reject!{|k,v| k==:synckey or k==:bundled or k==:id}
  put('', remote)
end