Class: BigKeeper::BigkeeperParser
- Inherits:
-
Object
- Object
- BigKeeper::BigkeeperParser
- Defined in:
- lib/big_keeper/util/bigkeeper_parser.rb
Overview
Bigkeeper file parser
Constant Summary collapse
- @@config =
{}
- @@current_user =
''
Class Method Summary collapse
- .config ⇒ Object
- .definitely_exists?(path) ⇒ Boolean
- .home_git ⇒ Object
- .home_name ⇒ Object
- .home_pulls ⇒ Object
- .module_full_path(home_path, user_name, module_name) ⇒ Object
- .module_git(module_name) ⇒ Object
- .module_names ⇒ Object
- .module_path(user_name, module_name) ⇒ Object
- .module_pulls(module_name) ⇒ Object
- .parse(bigkeeper) ⇒ Object
- .parse_home(name, params) ⇒ Object
- .parse_modules ⇒ Object
- .parse_modules_pod(name, params) ⇒ Object
- .parse_pod(name, params) ⇒ Object
- .parse_source(name) ⇒ Object
- .parse_user(name) ⇒ Object
- .parse_user_pod(name, params) ⇒ Object
- .parse_version(name) ⇒ Object
- .sourcemodule_path ⇒ Object
- .verify_modules(modules) ⇒ Object
- .version ⇒ Object
Class Method Details
.config ⇒ Object
182 183 184 |
# File 'lib/big_keeper/util/bigkeeper_parser.rb', line 182 def self.config @@config end |
.definitely_exists?(path) ⇒ Boolean
53 54 55 56 57 58 |
# File 'lib/big_keeper/util/bigkeeper_parser.rb', line 53 def self.definitely_exists? path folder = File.dirname path filename = File.basename path # Unlike Ruby IO, ls, and find -f, this technique will fail to locate the file if the case is wrong: not %x( find "#{folder}" -name "#{filename}" ).empty? end |
.home_git ⇒ Object
124 125 126 |
# File 'lib/big_keeper/util/bigkeeper_parser.rb', line 124 def self.home_git() @@config[:home][:git] end |
.home_name ⇒ Object
120 121 122 |
# File 'lib/big_keeper/util/bigkeeper_parser.rb', line 120 def self.home_name @@config[:name] end |
.home_pulls ⇒ Object
128 129 130 |
# File 'lib/big_keeper/util/bigkeeper_parser.rb', line 128 def self.home_pulls() @@config[:home][:pulls] end |
.module_full_path(home_path, user_name, module_name) ⇒ Object
140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/big_keeper/util/bigkeeper_parser.rb', line 140 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.("#{home_path}/../#{module_name}") end end |
.module_git(module_name) ⇒ Object
164 165 166 |
# File 'lib/big_keeper/util/bigkeeper_parser.rb', line 164 def self.module_git(module_name) @@config[:modules][module_name][:git] end |
.module_names ⇒ Object
178 179 180 |
# File 'lib/big_keeper/util/bigkeeper_parser.rb', line 178 def self.module_names @@config[:modules].keys end |
.module_path(user_name, module_name) ⇒ Object
152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/big_keeper/util/bigkeeper_parser.rb', line 152 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
168 169 170 |
# File 'lib/big_keeper/util/bigkeeper_parser.rb', line 168 def self.module_pulls(module_name) @@config[:modules][module_name][:pulls] end |
.parse(bigkeeper) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/big_keeper/util/bigkeeper_parser.rb', line 36 def self.parse(bigkeeper) if @@config.empty? Logger.error("Can't find a Bigkeeper file in current directory.") if !BigkeeperParser.definitely_exists?(bigkeeper) 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
79 80 81 82 |
# File 'lib/big_keeper/util/bigkeeper_parser.rb', line 79 def self.parse_home(name, params) @@config[:home] = params @@config[:name] = name end |
.parse_modules ⇒ Object
110 111 112 113 114 |
# File 'lib/big_keeper/util/bigkeeper_parser.rb', line 110 def self.parse_modules modules = @@config[:modules] modules = {} if modules.nil? @@config[:modules] = modules end |
.parse_modules_pod(name, params) ⇒ Object
104 105 106 107 108 |
# File 'lib/big_keeper/util/bigkeeper_parser.rb', line 104 def self.parse_modules_pod(name, params) modules = @@config[:modules] modules[name] = params @@config[:modules] = modules end |
.parse_pod(name, params) ⇒ Object
84 85 86 87 88 89 90 91 92 |
# File 'lib/big_keeper/util/bigkeeper_parser.rb', line 84 def self.parse_pod(name, params) if params[:path] parse_user_pod(name, params) elsif params[:git] parse_modules_pod(name, params) else Logger.error(%(There should be ':path =>' or ':git =>' for pod #{name})) end end |
.parse_source(name) ⇒ Object
64 65 66 67 68 69 |
# File 'lib/big_keeper/util/bigkeeper_parser.rb', line 64 def self.parse_source(name) sources = [] sources << @@config[:source] sources << name @@config[:source] = sources end |
.parse_user(name) ⇒ Object
71 72 73 74 75 76 77 |
# File 'lib/big_keeper/util/bigkeeper_parser.rb', line 71 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
94 95 96 97 98 99 100 101 102 |
# File 'lib/big_keeper/util/bigkeeper_parser.rb', line 94 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
60 61 62 |
# File 'lib/big_keeper/util/bigkeeper_parser.rb', line 60 def self.parse_version(name) @@config[:version] = name end |
.sourcemodule_path ⇒ Object
132 133 134 135 136 137 138 |
# File 'lib/big_keeper/util/bigkeeper_parser.rb', line 132 def self.sourcemodule_path if @@config[:source] == nil return "" else @@config[:source].join(",").reverse.chop.reverse end end |
.verify_modules(modules) ⇒ Object
172 173 174 175 176 |
# File 'lib/big_keeper/util/bigkeeper_parser.rb', line 172 def self.verify_modules(modules) modules.each do |item| Logger.error("Can not find module #{item} in Bigkeeper file") unless @@config[:modules][item] end end |
.version ⇒ Object
116 117 118 |
# File 'lib/big_keeper/util/bigkeeper_parser.rb', line 116 def self.version @@config[:version] end |