Class: Perkins::Server
- Defined in:
- lib/perkins/server.rb
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
- #enqueue_git_clone(repo) ⇒ 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
211 212 213 214 215 216 217 218 219 220 221 222 |
# File 'lib/perkins/server.rb', line 211 def initialize(args={}) super return if args.blank? puts "PerkinsCI environment loaded on #{args[:host]}:#{args[:port]}".green app = Perkins::Application.instance 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
259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 |
# File 'lib/perkins/server.rb', line 259 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 #::Perkins::Server.run!(options) end |
.start_listener(app_config) ⇒ Object
284 285 286 287 288 289 290 |
# File 'lib/perkins/server.rb', line 284 def self.start_listener(app_config) fork do listener = ::Perkins::Listener.new listener.app = app_config listener.run! end end |
Instance Method Details
#build_data ⇒ Object
228 229 230 231 |
# File 'lib/perkins/server.rb', line 228 def build_data Repo.sync_github_repos(github_user) redirect "/me" end |
#default_data ⇒ Object
293 294 295 |
# File 'lib/perkins/server.rb', line 293 def default_data {author: "miguel michelson", year: Time.now.year, app: @app} end |
#enqueue_git_clone(repo) ⇒ Object
244 245 246 |
# File 'lib/perkins/server.rb', line 244 def enqueue_git_clone(repo) GitLoaderWorker.perform_async(repo.id ) end |
#find_repo(params) ⇒ Object
237 238 239 240 241 242 |
# File 'lib/perkins/server.rb', line 237 def find_repo(params) id = "#{params[:login]}/#{params[:name]}" repo = Repo.find_by(name: id) #repo.load_git #it seems that we dont need this here repo end |
#github_repos ⇒ Object
224 225 226 |
# File 'lib/perkins/server.rb', line 224 def github_repos @github_repos ||= persisted_repos.any? ? persisted_repos : build_data end |
#persisted_repos ⇒ Object
233 234 235 |
# File 'lib/perkins/server.rb', line 233 def persisted_repos Repo.synced_records end |
#request_badge(opts = {}) ⇒ Object
248 249 250 251 252 253 254 255 |
# File 'lib/perkins/server.rb', line 248 def request_badge(opts={}) begin url = URI.parse("https://img.shields.io/badge/build-#{opts[:status]}-#{opts[:color]}.svg?style=flat-square") result = Net::HTTP.get(url) rescue => e e end end |