Class: Ape::Ape
- Inherits:
-
Object
- Object
- Ape::Ape
- Defined in:
- lib/ape.rb
Constant Summary collapse
- @@home =
nil
Instance Attribute Summary collapse
-
#aperc ⇒ Object
readonly
Returns the value of attribute aperc.
-
#reporter ⇒ Object
readonly
Returns the value of attribute reporter.
Class Method Summary collapse
- .home ⇒ Object
- .home=(home) ⇒ Object
-
.home_directory ⇒ Object
recipe from cap.
Instance Method Summary collapse
-
#check(uri, username = nil, password = nil, requested_e_coll = nil, requested_m_coll = nil) ⇒ Object
Checks the AtomPub server at
uri
for sanity. - #check_manifest(validator) ⇒ Object
-
#initialize(args = {}) ⇒ Ape
constructor
Creates an Ape instance with options given in the
args
Hash. - #might_fail(uri) ⇒ Object
- #report(output = STDOUT) ⇒ Object
Constructor Details
#initialize(args = {}) ⇒ Ape
Creates an Ape instance with options given in the args
Hash.
Options
* :output - one of 'text' or 'html'. #report will output in this format. Defaults to 'html'.
* :debug - enables debug information at each step in the output
37 38 39 40 41 |
# File 'lib/ape.rb', line 37 def initialize(args = {}) output = args[:output] || 'html' @reporter = Reporter.instance(output, args) load File.join(Ape.home, 'aperc') if File.exist?(File.join(Ape.home, 'aperc')) end |
Instance Attribute Details
#aperc ⇒ Object (readonly)
Returns the value of attribute aperc.
16 17 18 |
# File 'lib/ape.rb', line 16 def aperc @aperc end |
#reporter ⇒ Object (readonly)
Returns the value of attribute reporter.
16 17 18 |
# File 'lib/ape.rb', line 16 def reporter @reporter end |
Class Method Details
.home ⇒ Object
23 24 25 |
# File 'lib/ape.rb', line 23 def self.home @@home || ENV["APE_HOME"] || File.join(home_directory,".ape") end |
.home=(home) ⇒ Object
19 20 21 |
# File 'lib/ape.rb', line 19 def self.home=(home) @@home = home end |
.home_directory ⇒ Object
recipe from cap
28 29 30 |
# File 'lib/ape.rb', line 28 def self.home_directory ENV["HOME"] || (ENV["HOMEPATH"] && "#{ENV["HOMEDRIVE"]}#{ENV["HOMEPATH"]}") || "/" end |
Instance Method Details
#check(uri, username = nil, password = nil, requested_e_coll = nil, requested_m_coll = nil) ⇒ Object
Checks the AtomPub server at uri
for sanity.
Options
* uri - the URI of the AtomPub server. Required.
* username - an optional username for authentication
* password - if a username is provided, a password is required. See Ape::Authent for more information.
* requested_e_coll - a preferred entry collection to check
* requested_m_coll - a preferred media collection to check
51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/ape.rb', line 51 def check(uri, username=nil, password=nil, requested_e_coll = nil, requested_m_coll = nil) @authent = Authent.new(username, password) reporter.header = uri ::Ape.conf[:REQUESTED_ENTRY_COLLECTION] = requested_e_coll if requested_e_coll ::Ape.conf[:REQUESTED_MEDIA_COLLECTION] = requested_m_coll if requested_m_coll begin might_fail(uri) rescue Exception reporter.error(self, "Ouch! Ape fall down go boom; details: " + "#{$!}\n#{$!.class}\n#{$!.backtrace}") end end |
#check_manifest(validator) ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/ape.rb', line 100 def check_manifest(validator) variables = {} manifest = validator.manifest variables[:service_doc] = @service if (manifest.include?(:service_doc)) manifest.delete(:service_doc) if (manifest.include?(:entry_collection)) variables[:entry_collection] = ::Ape.conf[:REQUESTED_ENTRY_COLLECTION].nil? ? @entry_collections.first : get_collection(@entry_collections, ::Ape.conf[:REQUESTED_ENTRY_COLLECTION]) manifest.delete(:entry_collection) end if (manifest.include?(:media_collection)) variables[:media_collection] = ::Ape.conf[:REQUESTED_MEDIA_COLLECTION].nil? ? @media_collections.first : get_collection(@media_collections, ::Ape.conf[:REQUESTED_MEDIA_COLLECTION]) manifest.delete(:media_collection) end manifest.each do |option| if (option.instance_of?(Hash)) all_collections = @entry_collections + @media_collections option.each do |key, value| unless (value.instance_of?(Hash)) #request a collection by its title, i.e: :entry_collection => 'Posts' variables[key] = get_collection(all_collections, value) else #request the first collection that matches the options, # i.e: :entry_collection => {:accept => 'image/png'} # :entry_collection => {:title => 'Atachments', :accept => 'video/*'} hash = value variables[key] = all_collections.select do |collection| matches = nil hash.each do |k, v| begin matches = eval("collection.#{k.to_s}", binding, __FILE__, __LINE__).index(v) rescue raise ValidationError, "collection attribute not found: #{k.to_s}" end end collection if matches end.first end end end end #ensure all variables are setted raise ValidationError, "#{manifest.join("\n")} haven't been setted" if variables.empty? variables.each do |k, v| raise ValidationError, "#{k} haven't been setted" unless v end variables end |
#might_fail(uri) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/ape.rb', line 66 def might_fail(uri) service_validator = Validator.instance(:service_document, @reporter, @authent) service_validator.validate(:uri => uri) @service = service_validator.service_document @entry_collections = service_validator.entry_collections @media_collections = service_validator.media_collections if @entry_collections && true != ::Ape.conf[:ENTRY_VALIDATION_DISABLED] [:entry_posts, :sorting, :sanitization].each do |option| check_validator(option) end else reporter.warning(self, "No collection for 'application/atom+xml;type=entry', won't test entry posting.") end if @media_collections && true != ::Ape.conf[:MEDIA_VALIDATION_DISABLED] [:media_posts, :media_linkage].each do |option| check_validator(option) end else reporter.warning(self, "No collection for 'image/jpeg', won't test media posting.") end #custom validators Validator.custom_validators(@reporter, @authent).each do |validator| opts = check_manifest(validator) break if !validator.validate(opts) && validator.deterministic? end end |
#report(output = STDOUT) ⇒ Object
96 97 98 |
# File 'lib/ape.rb', line 96 def report(output=STDOUT) @reporter.report(output) end |