Module: Bananajour

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

Defined Under Namespace

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

Constant Summary collapse

VERSION =
'2.6.8'

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



43
44
45
46
47
48
49
50
# File 'lib/bananajour.rb', line 43

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

.get_git_global_config(key) ⇒ Object



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

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

.git_uriObject



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

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

.host_nameObject



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/bananajour.rb', line 60

def host_name
  hn = get_git_global_config("bananajour.hostname")
  unless hn.nil? or hn.empty?
    return hn
  end

  hn = Socket.gethostname

  # if there is more than one period in the hostname then assume it's a FQDN
  # and the user knows what they're doing
  return hn if hn.count('.') > 1

  if hn =~ /\.local$/
    hn
  else
    hn + ".local"
  end
end

.pathObject



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

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

.repositoriesObject



83
84
85
# File 'lib/bananajour.rb', line 83

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

.repositories_pathObject



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

def repositories_path
  path + "repositories"
end

.repository(name) ⇒ Object



87
88
89
# File 'lib/bananajour.rb', line 87

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

.setup!Object



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

def setup!
  repositories_path.mkpath
end

.setup?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/bananajour.rb', line 23

def setup?
  repositories_path.exist?
end

.to_hashObject



91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/bananajour.rb', line 91

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



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

def web_port
  9331
end

.web_uriObject



56
57
58
# File 'lib/bananajour.rb', line 56

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