Permalink
Browse files

properly namespaced stuff

  • Loading branch information...
1 parent 7f97f7a commit a81e2d6a8085b291fbacb250fdcff6bdf001f11e @rubiii rubiii committed Feb 18, 2012
Showing with 81 additions and 75 deletions.
  1. +18 −16 application.rb
  2. +1 −1 config.ru
  3. +13 −11 lib/result.rb
  4. +49 −47 lib/validator.rb
View
@@ -3,28 +3,30 @@
require File.expand_path("lib/validator")
-module LintApp
- class Application < Sinatra::Base
+module Travis
+ module WebLint
+ class Application < Sinatra::Base
- register Sinatra::RespondTo
+ register Sinatra::RespondTo
- get "/" do
- haml :index
- end
+ get "/" do
+ haml :index
+ end
- post "/" do
- redirect to("/#{params['repo']}")
- end
+ post "/" do
+ redirect to("/#{params['repo']}")
+ end
- get "/*" do
- repo = params["splat"].first
- @result = Validator.validate(repo)
+ get "/*" do
+ repo = params["splat"].first
+ @result = Validator.validate(repo)
- respond_to do |wants|
- wants.html { haml :result }
- wants.json { @result.to_json }
+ respond_to do |wants|
+ wants.html { haml :result }
+ wants.json { @result.to_json }
+ end
end
- end
+ end
end
end
View
@@ -1,2 +1,2 @@
require File.expand_path("application")
-run LintApp::Application
+run Travis::WebLint::Application
View
@@ -1,17 +1,19 @@
-module LintApp
- Result = Struct.new(:type, :issues) do
+module Travis
+ module WebLint
+ Result = Struct.new(:type, :issues) do
- def valid?
- type == :valid
- end
+ def valid?
+ type == :valid
+ end
- def to_json
- if valid?
- { :valid => true }.to_json
- else
- { :valid => false, :issues => issues }.to_json
+ def to_json
+ if valid?
+ { :valid => true }.to_json
+ else
+ { :valid => false, :issues => issues }.to_json
+ end
end
- end
+ end
end
end
View
@@ -1,65 +1,67 @@
require "net/http"
require File.expand_path("lib/result")
-module LintApp
- module Validator
- extend self
+module Travis
+ module WebLint
+ module Validator
+ extend self
- class Error < StandardError; end
- class HTTPError < Error; end
- class JSONError < Error; end
- class YAMLError < Error; end
- class GithubError < Error; end
+ class Error < StandardError; end
+ class HTTPError < Error; end
+ class JSONError < Error; end
+ class YAMLError < Error; end
+ class GithubError < Error; end
- SHA_URI = "http://github.com/api/v2/json/commits/list/%s/master"
- BLOB_URI = "http://github.com/api/v2/json/blob/show/%s/%s/.travis.yml"
+ SHA_URI = "http://github.com/api/v2/json/commits/list/%s/master"
+ BLOB_URI = "http://github.com/api/v2/json/blob/show/%s/%s/.travis.yml"
- def validate(project)
- sha = get_sha(project)
- travis_blob = get_blob(project, sha)
- lint yaml_load(travis_blob)
- end
+ def validate(project)
+ sha = get_sha(project)
+ travis_blob = get_blob(project, sha)
+ lint yaml_load(travis_blob)
+ end
- private
+ private
- def get_sha(project)
- response = http_get(SHA_URI, project).body
- result = json_parse(response)
+ def get_sha(project)
+ response = http_get(SHA_URI, project).body
+ result = json_parse(response)
- raise GithubError, result["error"] if result["error"]
- result["commits"].first["tree"]
- end
+ raise GithubError, result["error"] if result["error"]
+ result["commits"].first["tree"]
+ end
- def get_blob(project, sha)
- response = http_get(BLOB_URI, project, sha).body
- result = json_parse(response)
- result["blob"]["data"]
- end
+ def get_blob(project, sha)
+ response = http_get(BLOB_URI, project, sha).body
+ result = json_parse(response)
+ result["blob"]["data"]
+ end
- def http_get(uri, *args)
- Net::HTTP.get_response URI(uri % args)
- rescue SocketError
- raise HTTPError
- end
+ def http_get(uri, *args)
+ Net::HTTP.get_response URI(uri % args)
+ rescue SocketError
+ raise HTTPError
+ end
- def json_parse(string)
- JSON.parse(string)
- rescue JSON::ParserError
- raise JSONError
- end
+ def json_parse(string)
+ JSON.parse(string)
+ rescue JSON::ParserError
+ raise JSONError
+ end
- def yaml_load(string)
- YAML.load(string)
- rescue ArgumentError, Psych::SyntaxError
- raise YAMLError
- end
+ def yaml_load(string)
+ YAML.load(string)
+ rescue ArgumentError, Psych::SyntaxError
+ raise YAMLError
+ end
- def lint(travis_yml)
- issues = Travis::Lint::Linter.validate(travis_yml)
+ def lint(travis_yml)
+ issues = Lint::Linter.validate(travis_yml)
- return Result.new(:issues, issues) unless issues.empty?
- Result.new(:valid)
- end
+ return Result.new(:issues, issues) unless issues.empty?
+ Result.new(:valid)
+ end
+ end
end
end

0 comments on commit a81e2d6

Please sign in to comment.