Module: Railsquest

Extended by:
Commands, DateHelpers, GravatarHelpers
Defined in:
lib/railsquest.rb,
lib/railsquest/badge.rb,
lib/railsquest/quest.rb,
lib/railsquest/helpers.rb,
lib/railsquest/version.rb

Defined Under Namespace

Modules: Bonjour, Commands, DateHelpers, GravatarHelpers Classes: Badge, Quest

Constant Summary collapse

VERSION =
'0.1'

Class Method Summary collapse

Methods included from Commands

add!, advertise!, init_success_message, plain_init_success_message, 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

.badgesObject



99
100
101
# File 'lib/railsquest.rb', line 99

def badges
   badges_path.children.reject{ |b| b.to_s =~ /DS_Store/}.map {|b| Badge.new(b).to_hash }
end

.badges_pathObject



43
44
45
# File 'lib/railsquest.rb', line 43

def badges_path
  path + "badges"
end

.configObject



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

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



47
48
49
# File 'lib/railsquest.rb', line 47

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

.host_nameObject



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/railsquest.rb', line 68

def host_name
  hn = get_git_global_config("railsquest.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



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

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

.quest(name) ⇒ Object



95
96
97
# File 'lib/railsquest.rb', line 95

def quest(name)
  quests.find {|r| r.name == name}
end

.quest_uriObject



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

def quest_uri
  "http://#{host_name}/"
end

.questsObject



91
92
93
# File 'lib/railsquest.rb', line 91

def quests
  quests_path.children.reject{ |b| b.to_s =~ /DS_Store/}.map {|q| Quest.new(q)  }
end

.quests_pathObject



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

def quests_path
  path + "quests"
end

.setup!Object



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

def setup!
  quests_path.mkpath
  badges_path.mkpath
end

.setup?Boolean

Returns:

  • (Boolean)


25
26
27
28
# File 'lib/railsquest.rb', line 25

def setup?
  quests_path.exist?
  badges_path.exist?
end

.to_hashObject



103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/railsquest.rb', line 103

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

.web_portObject



60
61
62
# File 'lib/railsquest.rb', line 60

def web_port
  9876
end

.web_uriObject



64
65
66
# File 'lib/railsquest.rb', line 64

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