Module: Bananajour

Extended by:
Commands, DateHelpers, GravatarHelpers
Defined in:
lib/bananajour.rb,
lib/bananajour/helpers.rb,
lib/bananajour/version.rb,
lib/bananajour/repository.rb,
lib/bananajour/gem_dependencies.rb

Defined Under Namespace

Modules: Bonjour, Commands, DateHelpers, GemDependencies, GravatarHelpers Classes: Repository

Constant Summary collapse

VERSION =
'2.1.9'

Class Method Summary collapse

Methods included from Commands

add!, advertise!, check_git!, check_git_config!, clone!, init_success_message, plain_init_success_message, serve_git!, serve_web!

Methods included from GravatarHelpers

gravatar, gravatar_uri

Methods included from DateHelpers

distance_of_time_in_words, time_ago_in_words

Class Method Details

.configObject



50
51
52
53
54
55
56
57
# File 'lib/bananajour.rb', line 50

def config
  @config ||= begin
    OpenStruct.new({
      :name => get_git_global_config("user.name"),
      :email => get_git_global_config("user.email")
    })
  end
end

.gem(name) ⇒ Object



27
28
29
# File 'lib/bananajour/gem_dependencies.rb', line 27

def self.gem(name)
  Bananajour::GemDependencies.for_name(name).require_gem
end

.get_git_global_config(key) ⇒ Object



46
47
48
# File 'lib/bananajour.rb', line 46

def get_git_global_config(key)
  `git config --global #{key}`.strip
end

.git_uriObject



71
72
73
# File 'lib/bananajour.rb', line 71

def git_uri
  "git://#{host_name}/"
end

.host_nameObject



67
68
69
# File 'lib/bananajour.rb', line 67

def host_name
  Socket.gethostname
end

.pathObject



38
39
40
# File 'lib/bananajour.rb', line 38

def path
  Fancypath("~/.bananajour").expand_path
end

.repositoriesObject



75
76
77
# File 'lib/bananajour.rb', line 75

def repositories
  repositories_path.children.map {|r| Repository.new(r)}.sort_by {|r| r.name}
end

.repositories_pathObject



42
43
44
# File 'lib/bananajour.rb', line 42

def repositories_path
  path/"repositories"
end

.repository(name) ⇒ Object



79
80
81
# File 'lib/bananajour.rb', line 79

def repository(name)
  repositories.find {|r| r.name == name}
end

.require_gem(name, lib = nil) ⇒ Object



30
31
32
33
# File 'lib/bananajour/gem_dependencies.rb', line 30

def self.require_gem(name, lib=nil)
  self.gem(name)
  Kernel.require(lib || name)
end

.setup!Object



34
35
36
# File 'lib/bananajour.rb', line 34

def setup!
  repositories_path.create_dir
end

.setup?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/bananajour.rb', line 30

def setup?
  repositories_path.exists?
end

.to_hashObject



83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/bananajour.rb', line 83

def to_hash
  {
    "name" => config.name,
    "email" => config.email,
    "uri"  => web_uri,
    "git-uri" => git_uri,
    "gravatar" => Bananajour.gravatar,
    "version" => Bananajour::VERSION,
    "repositories" => repositories.collect do |r|
      {"name" => r.name, "uri" => r.uri}
    end
  }
end

.web_portObject



59
60
61
# File 'lib/bananajour.rb', line 59

def web_port
  9331
end

.web_uriObject



63
64
65
# File 'lib/bananajour.rb', line 63

def web_uri
  "http://#{host_name}:#{web_port}/"
end