Class: BPCI::Server

Inherits:
Sinatra::Base
  • Object
show all
Defined in:
lib/bpci/server.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Server

Returns a new instance of Server.



79
80
81
82
83
# File 'lib/bpci/server.rb', line 79

def initialize(*args)
  super
  @bpci = BPCI.new(settings.project_path)
  check_project
end

Instance Attribute Details

#bpciObject (readonly)

Returns the value of attribute bpci.



7
8
9
# File 'lib/bpci/server.rb', line 7

def bpci
  @bpci
end

Class Method Details

.project_path=(project_path) ⇒ Object



96
97
98
99
100
101
102
103
104
105
# File 'lib/bpci/server.rb', line 96

def self.project_path=(project_path)
  user, pass = Config.bpci(project_path).user.to_s, Config.bpci(project_path).pass.to_s
  if user != '' && pass != ''
    use Rack::Auth::Basic do |username, password|
      [ username, password ] == [ user, pass ]
    end
    puts "Using HTTP basic auth"
  end
  set :project_path, Proc.new{project_path}, true
end

.rack_start(project_path) ⇒ Object



91
92
93
94
# File 'lib/bpci/server.rb', line 91

def self.rack_start(project_path)
  set :project_path, project_path
  self.new
end

.start(host, port, project_path) ⇒ Object



85
86
87
88
89
# File 'lib/bpci/server.rb', line 85

def self.start(host, port, project_path)
  set :project_path, project_path
  $port = port # TODO: Unglobal this.
  BPCI::Server.run! :host => host, :port => port
end

Instance Method Details

#check_projectObject



107
108
109
110
111
112
113
# File 'lib/bpci/server.rb', line 107

def check_project
  if settings.project_path.nil? || !File.exists?(File.expand_path(settings.project_path))
    puts "Whoops! I need the path to a Git repo."
    puts "  $ git clone [email protected]:username/project.git project"
    abort "  $ bpci project"
  end
end