Module: Bait

Extended by:
Assets
Defined in:
lib/bait.rb,
lib/bait/api.rb,
lib/bait/cli.rb,
lib/bait/build.rb,
lib/bait/phase.rb,
lib/bait/assets.rb,
lib/bait/object.rb,
lib/bait/pubsub.rb,
lib/bait/version.rb,
lib/bait/integrator.rb,
lib/bait/build_helper.rb,
lib/bait/simple_query.rb,
lib/bait/simplecov_support.rb

Defined Under Namespace

Modules: Assets, BuildHelper, CLI, SimpleCovSupport, SimpleQuery Classes: Api, Build, Integrator, Object, Phase

Constant Summary collapse

VERSION =
File.open(File.join(File.dirname(__FILE__), "..", "..", "VERSION")){|f| f.read.strip}
@@Subscribers =
[]

Class Method Summary collapse

Methods included from Assets

assets

Class Method Details

.add_subscriber(stream) ⇒ Object



6
7
8
# File 'lib/bait/pubsub.rb', line 6

def add_subscriber stream
  @@Subscribers << stream
end

.broadcast(*args) ⇒ Object



12
13
14
15
16
# File 'lib/bait/pubsub.rb', line 12

def broadcast *args
  @@Subscribers.each do |out|
    out << "data: #{args.to_json}\n\n"
  end
end

.consoleObject



52
53
54
# File 'lib/bait.rb', line 52

def console
  STDOUT
end

.db_dirObject



22
23
24
25
26
# File 'lib/bait.rb', line 22

def db_dir
  db_dir = File.join storage_dir, "databases"
  FileUtils.mkdir_p db_dir
  db_dir
end

.db_file(name) ⇒ Object



28
29
30
31
32
# File 'lib/bait.rb', line 28

def db_file name
  yaml_file = File.join db_dir, "#{name}.yaml"
  FileUtils.touch yaml_file
  yaml_file
end

.envObject



40
41
42
# File 'lib/bait.rb', line 40

def env
  ENV['RACK_ENV'] ||= 'production'
end

.homeObject



44
45
46
# File 'lib/bait.rb', line 44

def home
  File.join Etc.getpwuid.dir, '.bait'
end

.publicObject



48
49
50
# File 'lib/bait.rb', line 48

def public
  Pathname.new(File.join(File.dirname(__FILE__), 'bait', 'public'))
end

.remove_subscriber(stream) ⇒ Object



9
10
11
# File 'lib/bait/pubsub.rb', line 9

def remove_subscriber stream
  @@Subscribers.delete stream        
end

.storage_dirObject



16
17
18
19
20
# File 'lib/bait.rb', line 16

def storage_dir
  path = File.join("#{home}", "#{env}")
  FileUtils.mkdir_p path
  path
end

.storeObject



34
35
36
37
38
# File 'lib/bait.rb', line 34

def store
  @store ||= begin
    Moneta.new :YAML, :file => db_file("main")
  end
end