Module: Rhoconnect::Condition::SourceRequired

Included in:
Server
Defined in:
lib/rhoconnect/condition/source_required.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(base) ⇒ Object



6
7
8
# File 'lib/rhoconnect/condition/source_required.rb', line 6

def self.extended(base)
  base.include_source_required_condition
end

Instance Method Details

#include_source_required_conditionObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/rhoconnect/condition/source_required.rb', line 10

def include_source_required_condition
  set(:source_required) do |value|
    condition do
      if value
        catch_all do
          source = nil
          user = current_user
          # TODO - this should be removed when old routes are removed
          if params["cud"]
            cud_source_name = JSON.parse(params["cud"])["source_name"]
            params.merge!({:source_name => cud_source_name}) if cud_source_name
          end
          # resource name is the source
          if params[:source_name] and user
            source = Source.load(params[:source_name],
              {:user_id => user.,:app_id => APP_NAME})

            # if source does not exist create one for dynamic adapter
            unless source
              sconfig = Rhoconnect.source_config(params[:source_name])
              source = Source.create(sconfig.merge!({:name => params[:source_name]}),{:user_id => user., :app_id => APP_NAME})
              current_app.sources << source.name
            end
          else
            Rhoconnect.log "ERROR: Can't load source, no source_name provided.\n"
            raise ArgumentError.new(UNKNOWN_SOURCE)
          end
          #puts "loaded source: #{source.inspect}"
          env[CURRENT_SOURCE] = source
          # by default - all routes should have an access to the model
          # if the route require source
          @model = Rhoconnect::Model::Base.create(source)
        end
      end
    end
  end
end