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



166
167
168
# File 'lib/big_keeper/util/bigkeeper_parser.rb', line 166

def self.config
  @@config
end

.home_gitObject



112
113
114
# File 'lib/big_keeper/util/bigkeeper_parser.rb', line 112

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

.home_nameObject



108
109
110
# File 'lib/big_keeper/util/bigkeeper_parser.rb', line 108

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

.home_pullsObject



116
117
118
# File 'lib/big_keeper/util/bigkeeper_parser.rb', line 116

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

.module_full_path(home_path, user_name, module_name) ⇒ Object



124
125
126
127
128
129
130
131
132
133
134
# File 'lib/big_keeper/util/bigkeeper_parser.rb', line 124

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



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

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

.module_namesObject



162
163
164
# File 'lib/big_keeper/util/bigkeeper_parser.rb', line 162

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

.module_path(user_name, module_name) ⇒ Object



136
137
138
139
140
141
142
143
144
145
146
# File 'lib/big_keeper/util/bigkeeper_parser.rb', line 136

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



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

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

.parse(bigkeeper) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/big_keeper/util/bigkeeper_parser.rb', line 34

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 ')
    content.gsub!(/source\s/, 'BigKeeper::source ')
    eval content
    # p @@config
  end
end

.parse_home(name, params) ⇒ Object



67
68
69
70
# File 'lib/big_keeper/util/bigkeeper_parser.rb', line 67

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

.parse_modulesObject



98
99
100
101
102
# File 'lib/big_keeper/util/bigkeeper_parser.rb', line 98

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

.parse_modules_pod(name, params) ⇒ Object



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

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

.parse_pod(name, params) ⇒ Object



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

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_source(name) ⇒ Object



52
53
54
55
56
57
# File 'lib/big_keeper/util/bigkeeper_parser.rb', line 52

def self.parse_source(name)
  sources = []
  sources << @@config[:source]
  sources << name
  @@config[:source] = sources
end

.parse_user(name) ⇒ Object



59
60
61
62
63
64
65
# File 'lib/big_keeper/util/bigkeeper_parser.rb', line 59

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



82
83
84
85
86
87
88
89
90
# File 'lib/big_keeper/util/bigkeeper_parser.rb', line 82

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



48
49
50
# File 'lib/big_keeper/util/bigkeeper_parser.rb', line 48

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

.sourcemodule_pathObject



120
121
122
# File 'lib/big_keeper/util/bigkeeper_parser.rb', line 120

def self.sourcemodule_path
  @@config[:source].join(",").reverse.chop.reverse
end

.verify_modules(modules) ⇒ Object



156
157
158
159
160
# File 'lib/big_keeper/util/bigkeeper_parser.rb', line 156

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



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

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