Module: SvnWcBroker

Includes:
SvnRepoClient
Defined in:
lib/svn_wc_broker.rb

Overview

XXX/TODO docs;tests

Broker requests between web app (AJAX) to svn_wc_client

(this script is probably unnecessary and can be done away with it’s left over from an early design decision which has changed)

what it does: populate the top level array element with :run_error set to any exception that occurs: #repo==> “Error: #{e.message”}

Constant Summary collapse

SUPPORTED_ACTIONS =

any action we want to support gets added to this list – this list gets ‘evaled’ is why ++

%w(add commit delete info 
revert list ignore diff update 
status)

Constants included from SvnRepoClient

SvnRepoClient::STATUS_SPACER

Instance Method Summary collapse

Methods included from SvnRepoClient

#_collect_and_group, #_to_expected_json_format, #get_repo, #info_data, #repo_root, #svn_add, #svn_commit, #svn_delete, #svn_diff, #svn_ignore, #svn_info, #svn_list, #svn_revert, #svn_status, #svn_update

Instance Method Details

#debug_request(message) ⇒ Object



72
73
74
75
# File 'lib/svn_wc_broker.rb', line 72

def debug_request(message)
  resp_data = Array.new
  resp_data[0] = {:run_error => "Debug: #{message}"}
end

#do_requested_action(params) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/svn_wc_broker.rb', line 77

def do_requested_action(params)
  resp_data = Array.new

  action = params['svn_action'].to_s.strip.downcase
  files  = params['svn_files']

  begin
    if files and files.to_a.size > 0
      files_striped = ret_just_files_list(
                         process_params_to_list_of_files(files.to_s))
      @files = files_striped.to_a.uniq
      #@files.uniq
      #return svn_results debug_request(@files)

      # diff need status info
      if ('diff' == action ) 
         @files = process_params_to_list_of_files(files.to_s).to_a.uniq
      end

    end
    # eval known actions only
    # svn_list takes args # svn_status takes args
    if action == 'list' || action == 'status' 
      #eval("svn_#{action}('#{params['filter_re']}','#{params['filter_amt']}')")
      eval("svn_#{action}('#{params['filter_re']}','#{params['filter_amt']}','#{params['dir']}')")
    else
      # danger will robinson, only eval known supported actions
      eval("svn_#{action}") if SUPPORTED_ACTIONS.index(action)
    end
  rescue Exception => exn
    resp_data[0] = {:run_error => "Error: #{exn.message}"}
  end

end

#get_status_listObject

default action, always return the status list



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/svn_wc_broker.rb', line 113

def get_status_list
  svn_status_list = Array.new
  run_error = String.new

  begin
    svn_status_list = svn_status(params['filter_re'], params['filter_amt'], params['dir'])
  rescue Exception => e
    run_error <<  e.message
  end

  ##if svn_status_list.empty? or svn_status_list.size == 1
  ##if svn_status_list.empty?
  #if @entries_list[0][:entry_name].nil?
  #  svn_status_list[0] = {:repo_status => 'upto date',
  #                        :repo_root_local_path  => repo_root}
  #end
  
  if run_error.length > 0 
    svn_status_list[0] = {:run_error => run_error} 
  end

  svn_status_list
end

#handle_responses(params) ⇒ Object

pass web requests in, handle defined actions, return results params can be a cgi request object, or a rails request object, whatever contains our web POST request



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/svn_wc_broker.rb', line 49

def handle_responses(params)

    #--
    # to debug during devel
    #return svn_results debug_request(params['do_svn_action'])
    #return svn_results debug_request(params.to_s.to_a)
    #++
    if params['do_svn_action'] \
       && (params['do_svn_action'].to_s == 'Do Svn Action')
    
      #return svn_results debug_request(params)
      if params and params['svn_action'].to_s.strip.empty?
        return svn_results 
      else
        return svn_results( send(:do_requested_action, params) )
      end

    else 
      return svn_results
    end

end

#process_params_to_list_of_files(passed_file_list) ⇒ Object

clean up POST requests



143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/svn_wc_broker.rb', line 143

def process_params_to_list_of_files(passed_file_list) # :nodoc:
    if passed_file_list and passed_file_list.match(/,/)
      passed_file_list = passed_file_list.split(/,/).to_a
    end

    passed_file_list_cleaned = Array.new
    passed_file_list.each do |f_list_str|
      # cgi params cleanup
      # i.e. substituting the cgi with another 'http request broker'
      #f_list_str.gsub!(/((\302\240)+|\t+|\s+)/, "\s")#&nbsp; becomes odd 2 byte char
      f_list_str.gsub!(/((\302\240)+|\t+|\s+)/, "\s")#&nbsp; becomes odd 2 byte char
      passed_file_list_cleaned.push f_list_str
    end
    passed_file_list_cleaned
end

#ret_just_files_list(file_status_list) ⇒ Object

:nodoc:



159
160
161
162
163
164
165
166
167
# File 'lib/svn_wc_broker.rb', line 159

def ret_just_files_list(file_status_list) # :nodoc:
  just_files = Array.new
  return file_status_list unless file_status_list.class == Array
  file_status_list.each do |f_list_str|
    f_stat, f_name = f_list_str.split(/\s/)
    just_files.push(f_name)
  end
  just_files
end

#set_conf_file(conf) ⇒ Object

set abs_path to your configuration file



41
# File 'lib/svn_wc_broker.rb', line 41

def set_conf_file(conf) ; @conf_file = conf ; end

#svn_results(data = []) ⇒ Object

svn_wc_broker always returns results, data if set, otherwise svn status list



138
139
140
# File 'lib/svn_wc_broker.rb', line 138

def svn_results(data=[])
   if data.empty? then get_status_list else data end
end