Class: Rhosync::SourceAdapter

Inherits:
Object
  • Object
show all
Defined in:
lib/rhosync/test_methods.rb,
lib/rhosync/source_adapter.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, credential = nil) ⇒ SourceAdapter

Returns a new instance of SourceAdapter.



16
17
18
# File 'lib/rhosync/source_adapter.rb', line 16

def initialize(source,credential=nil)
  @source = source
end

Instance Attribute Details

#resultObject

Returns the value of attribute result.



3
4
5
# File 'lib/rhosync/test_methods.rb', line 3

def result
  @result
end

#sessionObject

Returns the value of attribute session.



14
15
16
# File 'lib/rhosync/source_adapter.rb', line 14

def session
  @session
end

Class Method Details

.create(source, credential = nil) ⇒ Object

Returns an instance of a SourceAdapter by source name



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/rhosync/source_adapter.rb', line 21

def self.create(source,credential=nil)
  adapter=nil
  if source
    begin
      source.name.strip! if source.name
      require under_score(source.name)
      adapter=(Object.const_get(source.name)).new(source,credential) 
    rescue Exception=>e
      log "Failure to create adapter from class #{source.name}: #{e.inspect.to_s}"
      raise e
    end
  end
  adapter
end

Instance Method Details

#ask(params = nil) ⇒ Object



85
# File 'lib/rhosync/source_adapter.rb', line 85

def ask(params=nil); end

#create(name_value_list) ⇒ Object



79
# File 'lib/rhosync/source_adapter.rb', line 79

def create(name_value_list); end

#delete(name_value_list) ⇒ Object



83
# File 'lib/rhosync/source_adapter.rb', line 83

def delete(name_value_list); end

#do_query(params = nil) ⇒ Object



61
62
63
64
65
66
# File 'lib/rhosync/source_adapter.rb', line 61

def do_query(params=nil)
  @tmp_docname = @source.docname(:md) + get_random_uuid
  @stash_size = 0
  params ? self.query(params) : self.query
  self.sync
end

#expire_bulk_data(partition = :user) ⇒ Object



75
76
77
# File 'lib/rhosync/source_adapter.rb', line 75

def expire_bulk_data(partition = :user)
  Rhosync.expire_bulk_data(current_user.,partition)
end

#loginObject



36
# File 'lib/rhosync/source_adapter.rb', line 36

def ; end

#logoffObject



87
# File 'lib/rhosync/source_adapter.rb', line 87

def logoff; end

#query(params = nil) ⇒ Object



38
# File 'lib/rhosync/source_adapter.rb', line 38

def query(params=nil); end

#save(docname) ⇒ Object



89
90
91
92
93
94
95
96
# File 'lib/rhosync/source_adapter.rb', line 89

def save(docname)
  return if @result.nil?
  if @result.empty?
    Store.flash_data(docname)
  else
    Store.put_data(docname,@result)
  end
end

#search(params = nil) ⇒ Object



40
# File 'lib/rhosync/source_adapter.rb', line 40

def search(params=nil); end

#stash_resultObject



68
69
70
71
72
73
# File 'lib/rhosync/source_adapter.rb', line 68

def stash_result
  return if @result.nil?
  Store.put_data(@tmp_docname,@result,true)
  @stash_size += @result.size
  @result = nil
end

#syncObject



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/rhosync/source_adapter.rb', line 42

def sync
  if @result and @result.empty?
    @source.lock(:md) do |s|
      s.flash_data(:md)
      s.put_value(:md_size,0)
    end
  else
    if @result
      Store.put_data(@tmp_docname,@result) 
      @stash_size += @result.size
    end  
    @source.lock(:md) do |s|
      s.flash_data(:md)
      Store.rename(@tmp_docname,s.docname(:md))
      s.put_value(:md_size,@stash_size)
    end
  end
end

#update(name_value_list) ⇒ Object



81
# File 'lib/rhosync/source_adapter.rb', line 81

def update(name_value_list); end