Class: BigKeeper::BigkeeperParser

Inherits:
Object
  • Object
show all
Defined in:
lib/big_keeper/util/bigkeeper_parser.rb

Overview

Bigkeeper file parser

Constant Summary collapse

@@config =
{}
@@current_user =
''

Class Method Summary collapse

Class Method Details

.configObject



151
152
153
# File 'lib/big_keeper/util/bigkeeper_parser.rb', line 151

def self.config
  @@config
end

.home_gitObject



101
102
103
# File 'lib/big_keeper/util/bigkeeper_parser.rb', line 101

def self.home_git()
  @@config[:home][:git]
end

.home_nameObject



97
98
99
# File 'lib/big_keeper/util/bigkeeper_parser.rb', line 97

def self.home_name
  @@config[:name]
end

.home_pullsObject



105
106
107
# File 'lib/big_keeper/util/bigkeeper_parser.rb', line 105

def self.home_pulls()
  @@config[:home][:pulls]
end

.module_full_path(home_path, user_name, module_name) ⇒ Object



109
110
111
112
113
114
115
116
117
118
119
# File 'lib/big_keeper/util/bigkeeper_parser.rb', line 109

def self.module_full_path(home_path, user_name, module_name)
  if @@config[:users] \
    && @@config[:users][user_name] \
    && @@config[:users][user_name][:pods] \
    && @@config[:users][user_name][:pods][module_name] \
    && @@config[:users][user_name][:pods][module_name][:path]
    @@config[:users][user_name][:pods][module_name][:path]
  else
    File.expand_path("#{home_path}/../#{module_name}")
  end
end

.module_git(module_name) ⇒ Object



133
134
135
# File 'lib/big_keeper/util/bigkeeper_parser.rb', line 133

def self.module_git(module_name)
  @@config[:modules][module_name][:git]
end

.module_namesObject



147
148
149
# File 'lib/big_keeper/util/bigkeeper_parser.rb', line 147

def self.module_names
  @@config[:modules].keys
end

.module_path(user_name, module_name) ⇒ Object



121
122
123
124
125
126
127
128
129
130
131
# File 'lib/big_keeper/util/bigkeeper_parser.rb', line 121

def self.module_path(user_name, module_name)
  if @@config[:users] \
    && @@config[:users][user_name] \
    && @@config[:users][user_name][:pods] \
    && @@config[:users][user_name][:pods][module_name] \
    && @@config[:users][user_name][:pods][module_name][:path]
    @@config[:users][user_name][:pods][module_name][:path]
  else
    "../#{module_name}"
  end
end

.module_pulls(module_name) ⇒ Object



137
138
139
# File 'lib/big_keeper/util/bigkeeper_parser.rb', line 137

def self.module_pulls(module_name)
  @@config[:modules][module_name][:pulls]
end

.parse(bigkeeper) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/big_keeper/util/bigkeeper_parser.rb', line 30

def self.parse(bigkeeper)
  if @@config.empty?
    content = File.read bigkeeper

    content.gsub!(/version\s/, 'BigKeeper::version ')
    content.gsub!(/user\s/, 'BigKeeper::user ')
    content.gsub!(/home\s/, 'BigKeeper::home ')
    content.gsub!(/pod\s/, 'BigKeeper::pod ')
    content.gsub!(/modules\s/, 'BigKeeper::modules ')
    eval content
    # p @@config
  end
end

.parse_home(name, params) ⇒ Object



56
57
58
59
# File 'lib/big_keeper/util/bigkeeper_parser.rb', line 56

def self.parse_home(name, params)
  @@config[:home] = params
  @@config[:name] = name
end

.parse_modulesObject



87
88
89
90
91
# File 'lib/big_keeper/util/bigkeeper_parser.rb', line 87

def self.parse_modules
  modules = @@config[:modules]
  modules = {} if modules.nil?
  @@config[:modules] = modules
end

.parse_modules_pod(name, params) ⇒ Object



81
82
83
84
85
# File 'lib/big_keeper/util/bigkeeper_parser.rb', line 81

def self.parse_modules_pod(name, params)
  modules = @@config[:modules]
  modules[name] = params
  @@config[:modules] = modules
end

.parse_pod(name, params) ⇒ Object



61
62
63
64
65
66
67
68
69
# File 'lib/big_keeper/util/bigkeeper_parser.rb', line 61

def self.parse_pod(name, params)
  if params[:path]
    parse_user_pod(name, params)
  elsif params[:git]
    parse_modules_pod(name, params)
  else
    raise %(There should be ':path =>' or ':git =>' for pod #{name})
  end
end

.parse_user(name) ⇒ Object



48
49
50
51
52
53
54
# File 'lib/big_keeper/util/bigkeeper_parser.rb', line 48

def self.parse_user(name)
  @@current_user = name
  users = @@config[:users]
  users = {} if users.nil?
  users[name] = {}
  @@config[:users] = users
end

.parse_user_pod(name, params) ⇒ Object



71
72
73
74
75
76
77
78
79
# File 'lib/big_keeper/util/bigkeeper_parser.rb', line 71

def self.parse_user_pod(name, params)
  users = @@config[:users]
  user = users[@@current_user]
  pods = user[:pods]
  pods = {} if pods.nil?
  pods[name] = params
  user[:pods] = pods
  @@config[:users] = users
end

.parse_version(name) ⇒ Object



44
45
46
# File 'lib/big_keeper/util/bigkeeper_parser.rb', line 44

def self.parse_version(name)
  @@config[:version] = name
end

.verify_modules(modules) ⇒ Object



141
142
143
144
145
# File 'lib/big_keeper/util/bigkeeper_parser.rb', line 141

def self.verify_modules(modules)
  modules.each do |item|
    raise "Can not find module #{item} in Bigkeeper file" unless @@config[:modules][item]
  end
end

.versionObject



93
94
95
# File 'lib/big_keeper/util/bigkeeper_parser.rb', line 93

def self.version
  @@config[:version]
end