Class: Perkins::Server
- Defined in:
- lib/perkins/server.rb
Constant Summary collapse
- @@conns =
[]
Instance Attribute Summary collapse
-
#app ⇒ Object
readonly
Returns the value of attribute app.
Class Method Summary collapse
-
.start(app, options) ⇒ Object
TODO: deprecate this.
- .start_listener(app_config) ⇒ Object
Instance Method Summary collapse
- #build_data ⇒ Object
- #default_data ⇒ Object
- #find_repo(params) ⇒ Object
- #github_repos ⇒ Object
-
#initialize(args = {}) ⇒ Server
constructor
A new instance of Server.
- #persisted_repos ⇒ Object
- #request_badge(opts = {}) ⇒ Object
Constructor Details
#initialize(args = {}) ⇒ Server
Returns a new instance of Server.
211 212 213 214 215 216 217 218 219 220 221 222 223 224 |
# 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 |
Instance Attribute Details
#app ⇒ Object (readonly)
Returns the value of attribute app.
19 20 21 |
# File 'lib/perkins/server.rb', line 19 def app @app end |
Class Method Details
.start(app, options) ⇒ Object
TODO: deprecate this
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 |
# File 'lib/perkins/server.rb', line 257 def self.start(app, ) = .dup ENV['RACK_ENV'] = .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 |
Instance Method Details
#build_data ⇒ Object
230 231 232 233 |
# File 'lib/perkins/server.rb', line 230 def build_data Repo.sync_github_repos(github_user) redirect "/me" end |
#default_data ⇒ Object
289 290 291 |
# File 'lib/perkins/server.rb', line 289 def default_data { year: Time.now.year, app: @app} end |
#find_repo(params) ⇒ Object
239 240 241 242 243 |
# 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 ⇒ Object
226 227 228 |
# File 'lib/perkins/server.rb', line 226 def github_repos @github_repos ||= persisted_repos.any? ? persisted_repos : build_data end |
#persisted_repos ⇒ Object
235 236 237 |
# File 'lib/perkins/server.rb', line 235 def persisted_repos Repo.synced_records end |
#request_badge(opts = {}) ⇒ Object
245 246 247 248 249 250 251 252 253 |
# 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 |