Class: Ape::ServiceDocumentValidator

Inherits:
Validator
  • Object
show all
Defined in:
lib/ape/validators/service_document_validator.rb

Instance Attribute Summary collapse

Attributes inherited from Validator

#authent, #reporter

Instance Method Summary collapse

Methods inherited from Validator

custom_validators, instance

Methods included from Util

extended, included

Methods included from ValidatorDsl

included

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Ape::Validator

Instance Attribute Details

#entry_collectionsObject (readonly)

Returns the value of attribute entry_collections.



5
6
7
# File 'lib/ape/validators/service_document_validator.rb', line 5

def entry_collections
  @entry_collections
end

#media_collectionsObject (readonly)

Returns the value of attribute media_collections.



5
6
7
# File 'lib/ape/validators/service_document_validator.rb', line 5

def media_collections
  @media_collections
end

#service_documentObject (readonly)

Returns the value of attribute service_document.



5
6
7
# File 'lib/ape/validators/service_document_validator.rb', line 5

def service_document
  @service_document
end

Instance Method Details

#init_service_collections(uri) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/ape/validators/service_document_validator.rb', line 28

def init_service_collections(uri)
  # * Do we have collections we can post an entry and a picture to?
  #   the requested_* arguments are the requested collection titles; if
  #    provided, try to match them, otherwise just pick the first listed
  #
  collections = @service_document.collections
  if collections.length > 0

    reporter.start_list(self, "Found these collections")
    collections.each do |collection|
      reporter.list_item("'#{collection.title}' " +
          "accepts #{collection.accept.join(', ')}")
        
      if collection.accept?(Names::AtomEntryMediaType)
        @entry_collections ||= []
        @entry_collections << collection
      end
        
      if collection.accept?('image/jpeg')
        @media_collections ||= []
        @media_collections << collection
      end
    end
  end
end

#init_service_document(uri) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/ape/validators/service_document_validator.rb', line 12

def init_service_document(uri)
  reporter.info(self, "TESTING: Service document and collections.")
  
  begin
    @service_document = Service.new(:uri => uri, :reporter => reporter )
  rescue Exception
    prob = $!.to_s.gsub(/\n/, '<br/>')
    reporter.error(self, "Service document not usable: #{prob}")
    return
  end

  # RNC-validate the service doc
  Validator.instance(:schema, @reporter).validate(:schema => Samples.service_RNC, 
    :title => 'Service doc', :doc => @service_document.service)
end

#validate(opts = {}) ⇒ Object



7
8
9
10
# File 'lib/ape/validators/service_document_validator.rb', line 7

def validate(opts = {})
  init_service_document(opts[:uri])
  init_service_collections(opts[:uri]) if @service_document
end