Module: RESTRack

Defined in:
lib/restrack/support.rb,
lib/restrack/version.rb,
lib/restrack/response.rb,
lib/restrack/generator.rb,
lib/restrack/web_service.rb,
lib/restrack/resource_request.rb,
lib/restrack/async_web_service.rb,
lib/restrack/resource_relations.rb,
lib/restrack/resource_controller.rb

Defined Under Namespace

Modules: ResourceRelations Classes: AsyncWebService, Generator, ResourceController, ResourceRequest, Response, WebService

Constant Summary collapse

VERSION =
"1.8.2"

Class Method Summary collapse

Class Method Details

.controller_class_for(resource_name) ⇒ Object



41
42
43
# File 'lib/restrack/support.rb', line 41

def self.controller_class_for(resource_name)
  Kernel.const_get( RESTRack::CONFIG[:SERVICE_NAME].to_sym ).const_get( controller_name(resource_name).to_sym )
end

.controller_exists?(resource_name) ⇒ Boolean

Returns:

  • (Boolean)


33
34
35
36
37
38
39
# File 'lib/restrack/support.rb', line 33

def self.controller_exists?(resource_name)
  begin
    return Kernel.const_get( RESTRack::CONFIG[:SERVICE_NAME].to_sym ).const_defined?( controller_name(resource_name).to_sym )
  rescue # constants can't start with numerics
    return false
  end
end

.controller_has_action?(resource_name, action) ⇒ Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/restrack/support.rb', line 49

def self.controller_has_action?(resource_name, action)
  controller_class_for(resource_name).const_defined?( action.to_sym )
end

.controller_name(resource_name) ⇒ Object



45
46
47
# File 'lib/restrack/support.rb', line 45

def self.controller_name(resource_name)
  "#{resource_name.to_s.camelize}Controller".to_sym
end

.load_config(file) ⇒ Object

of class methods



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/restrack/support.rb', line 11

def self.load_config(file)
  config = YAML.load_file(file)
  # Open the logs on spin up.
  @@log                 ||= Logger.new( config[:LOG] )
  @@log.level             = Logger.const_get( config[:LOG_LEVEL] )
  @@request_log         ||= Logger.new( config[:REQUEST_LOG] )
  @@request_log.level     = Logger.const_get( config[:REQUEST_LOG_LEVEL] )
  # Do config validations
  if config[:ROOT_RESOURCE_ACCEPT].is_a?(Array) and config[:ROOT_RESOURCE_ACCEPT].length == 1 and config[:ROOT_RESOURCE_ACCEPT][0].lstrip.rstrip == ''
    config[:ROOT_RESOURCE_ACCEPT] = nil
    @@log.warn 'Improper format for RESTRack::CONFIG[:ROOT_RESOURCE_ACCEPT], should be nil or empty array not array containing empty string.'
  end
  if not config[:ROOT_RESOURCE_ACCEPT].blank? and not config[:DEFAULT_RESOURCE].blank? and not config[:ROOT_RESOURCE_ACCEPT].include?( config[:DEFAULT_RESOURCE] )
    @@log.warn 'RESTRack::CONFIG[:DEFAULT_RESOURCE] should be a member of RESTRack::CONFIG[:ROOT_RESOURCE_ACCEPT].'
  end
  config
end

.logObject



7
# File 'lib/restrack/support.rb', line 7

def log; @@log; end

.mime_type_for(format) ⇒ Object



29
30
31
# File 'lib/restrack/support.rb', line 29

def self.mime_type_for(format)
  MIME::Types.type_for(format.to_s.downcase)[0]
end

.request_logObject



8
# File 'lib/restrack/support.rb', line 8

def request_log; @@request_log; end