class Perkins::Server
Attributes
app[R]
Public Class Methods
new(args={})
click to toggle source
Calls superclass method
# File lib/perkins/server.rb, line 211 def initialize(args={}) super #return if args.blank? app = Perkins::Application.instance puts "PerkinsCI #{settings.environment} environment loaded on #{app.host}:#{app.port}".green self.class.set :perkins_application, app self.class.set :github_options, { :scopes => "admin:repo_hook,repo,user:email", :secret => app.github_client_secret, :client_id => app.github_client_id, } end
start(app, options)
click to toggle source
TODO: deprecate this
# File lib/perkins/server.rb, line 257 def self.start(app, options) options = options.dup ENV['RACK_ENV'] = options.delete("e") register Sinatra::ActiveRecordExtension app = app.is_a?(String) ? eval(File.open(app).read) : app self.start_listener(app) configure :development do #register Sinatra::Reloader #set :database, 'sqlite:///db/development.sqlite3' end configure :production do #set :database, 'sqlite:///db/productions.sqlite3' end configure :test do #set :database, 'sqlite:///db/test.sqlite3' end end
start_listener(app_config)
click to toggle source
# File lib/perkins/server.rb, line 280 def self.start_listener(app_config) fork do listener = ::Perkins::Listener.new listener.app = app_config listener.run! end end
Public Instance Methods
avatar_url(email, size)
click to toggle source
# File lib/perkins/server.rb, line 304 def avatar_url(email, size) gravatar_id = Digest::MD5.hexdigest(email.downcase) "http://gravatar.com/avatar/#{gravatar_id}.png?s=#{size}" end
build_data()
click to toggle source
# File lib/perkins/server.rb, line 230 def build_data Repo.sync_github_repos(github_user) redirect "/me" end
commit_url(repo, sha)
click to toggle source
# File lib/perkins/server.rb, line 309 def commit_url(repo, sha) "#{repo.http_url}/commit/#{sha}" end
default_data()
click to toggle source
# File lib/perkins/server.rb, line 289 def default_data { year: Time.now.year, app: @app} end
find_repo(params)
click to toggle source
# File lib/perkins/server.rb, line 239 def find_repo(params) id = "#{params[:login]}/#{params[:name]}" repo = Repo.find_by(name: id) repo end
github_repos()
click to toggle source
# File lib/perkins/server.rb, line 226 def github_repos @github_repos ||= persisted_repos.any? ? persisted_repos : build_data end
persisted_repos()
click to toggle source
# File lib/perkins/server.rb, line 235 def persisted_repos Repo.synced_records end
request_badge(opts={})
click to toggle source
# File lib/perkins/server.rb, line 245 def request_badge(opts={}) begin image_path = "https://img.shields.io/badge/build-#{opts[:status]}-#{opts[:color]}.svg?style=flat-square" url = URI.parse(image_path) result = Net::HTTP.get(url) rescue => e e end end
status_class(status)
click to toggle source
# File lib/perkins/server.rb, line 300 def status_class(status) status ? "glyphicon glyphicon-ok" : "glyphicon glyphicon-remove" end
status_label(status)
click to toggle source
# File lib/perkins/server.rb, line 294 def status_label(status) label = status == true ? "success" : "default" msg = status ? "passed" : "error" "<span class='label label-#{label}'>build | #{msg}</span>" end