Class: Rhoconnect::Controller::JsBase

Inherits:
Base
  • Object
show all
Defined in:
lib/rhoconnect/controller/js_base.rb

Direct Known Subclasses

JsAppBase

Constant Summary

Constants included from Rhoconnect

API_TOKEN_HEADER, API_VERSION, APP_NAME, Rhoconnect::CLIENT_ID_HEADER, Rhoconnect::CURRENT_APP, Rhoconnect::CURRENT_CLIENT, Rhoconnect::CURRENT_REQUEST, Rhoconnect::CURRENT_SOURCE, Rhoconnect::CURRENT_USER, PAGE_OBJECT_COUNT_HEADER, PAGE_TOKEN_HEADER, QUERY_RES, SYNC_VERSION, SourceAdapter, SourceAdapterException, SourceAdapterLoginException, SourceAdapterLogoffException, SourceAdapterObjectConflictErrorException, SourceAdapterServerErrorException, SourceAdapterServerTimeoutException, UNKNOWN_CLIENT, UNKNOWN_SOURCE, VERSION

Class Method Summary collapse

Methods inherited from Base

_add_route, _rest_name, delete, get, post, put, rest_path

Methods inherited from Server

_use_async_framework, api4, new, paths, set_default

Methods included from Rhoconnect::Condition::AdminRequired

extended, #include_admin_required_condition

Methods included from Rhoconnect::Condition::LoginRequired

extended, #include_login_required_condition

Methods included from Rhoconnect::Condition::SourceRequired

extended, #include_source_required_condition

Methods included from Rhoconnect::Condition::ClientRequired

extended, #include_client_required_condition

Methods included from Rhoconnect::Condition::Verbs

extended, #include_verbs_condition

Methods included from Rhoconnect::Condition::VerifySuccess

extended, #include_verify_success_condition

Methods included from Rhoconnect::Condition::AddParameter

extended, #include_add_parameter_condition

Methods included from Handler::Authenticate::ExecuteMethods

#execute_admin_authenticate_handler, #execute_authenticate_handler, #execute_rps_authenticate_handler

Methods included from Handler::PluginCallbacks::ExecuteMethods

#do_fast_delete, #do_fast_insert, #do_fast_update, #execute_push_objects_handler

Methods included from Handler::Search::ExecuteMethods

#execute_search_handler

Methods included from Handler::Changes::ExecuteMethods

#_extract_cud_params, #_run_cud_handler, #execute_create_handler, #execute_cud_handler, #execute_delete_handler, #execute_update_handler

Methods included from Handler::Query::ExecuteMethods

#execute_query_handler

Methods included from Rhoconnect

#add_to_url_map, #app, #bootstrap, #camelize, #check_and_add, #check_default_secret!, #check_for_schema_field!, #create_admin_user, #create_predefined_source, #environment, #expire_bulk_data, #get_config, #get_random_identifier, #get_token, #getelement, #lap_timer, #log, #register_predefined_source, #remove_from_url_map, #setelement, settings, shutdown, #source_config, #start_app, #start_nodejs_channels, #start_timer, #timenow, #under_score, #unzip_file, #url_map, #which

Class Method Details

._prefixObject



91
92
93
# File 'lib/rhoconnect/controller/js_base.rb', line 91

def self._prefix
  "app/#{Rhoconnect::API_VERSION}"
end

.hshify(str) ⇒ Object



69
70
71
# File 'lib/rhoconnect/controller/js_base.rb', line 69

def self.hshify(str)
  JSON.parse(str, :symbolize_names => true)
end

.js_block(key, finish_block = nil) ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/rhoconnect/controller/js_base.rb', line 73

def self.js_block(key,finish_block=nil)
  Proc.new do
    json = {
       :url   => key,
       :args  => params,
       :model => under_score(params[:source_name]),
       :route => 'request'
    }
    json[:user] = @model.current_user. if @model
    return_value = NodeChannel.publish_channel_and_wait(json,@model || self)
    if finish_block
      self.send(finish_block, return_value)
    else
      return_value
    end
  end
end

.process_defaults(klass, defaults) ⇒ Object



45
46
47
48
49
50
51
# File 'lib/rhoconnect/controller/js_base.rb', line 45

def self.process_defaults(klass,defaults)
  defaults.each do |default|
    default.each do |key,val|
      klass.send(:set_default,key.to_sym,val)
    end
  end
end

.process_routes(klass, routes) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/rhoconnect/controller/js_base.rb', line 53

def self.process_routes(klass,routes)
  routes.each do |r|
    opts = {}
    s_route = r.split('_rjs_')
    verb = s_route[0]
    action = s_route[2]
    opts = hshify(s_route[3]) if s_route[3]
    block = js_block(r)
    case opts[:rc_handler]
    when 'query'
      block = js_block(r,:query_finish)
    end
    klass.send(verb,action,opts,&block)
  end
end

.register_routes(json) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/rhoconnect/controller/js_base.rb', line 22

def self.register_routes(json)
  Rhoconnect::Model::JsBase.register_models(json['models'])
  json['result'].each do |key,val|
    controller_name = "#{key}Controller"
    next if Object.const_defined?(controller_name)
    if controller_name == 'ApplicationController'
      klass = Object.const_set(controller_name, Class.new(Rhoconnect::Controller::JsAppBase))
    else
      klass = Object.const_set(controller_name, Class.new(Rhoconnect::Controller::JsBase))
    end
    Rhoconnect.add_to_url_map(klass)
    process_defaults(klass,val['defaults'])
    process_routes(klass,val['routes'])

    # add PluginCallback routes (but only for Adapter Controllers)
    unless controller_name == "ApplicationController"
      klass.register Rhoconnect::Handler::PluginCallbacks
    end
  end
end