Class: Vim::Flavor::FlavorFile
- Inherits:
-
Object
- Object
- Vim::Flavor::FlavorFile
- Defined in:
- lib/vim-flavor.rb
Instance Attribute Summary collapse
-
#flavors ⇒ Object
readonly
Returns the value of attribute flavors.
Instance Method Summary collapse
- #eval_flavorfile(flavorfile_path) ⇒ Object
- #flavor(repo_name, *args) ⇒ Object
- #group(*group_names, &block) ⇒ Object
-
#initialize ⇒ FlavorFile
constructor
A new instance of FlavorFile.
- #interpret(&block) ⇒ Object
- #repo_uri_from_repo_name(repo_name) ⇒ Object
Constructor Details
#initialize ⇒ FlavorFile
Returns a new instance of FlavorFile.
181 182 183 184 |
# File 'lib/vim-flavor.rb', line 181 def initialize() @flavors = {} @default_groups = [:default] end |
Instance Attribute Details
#flavors ⇒ Object (readonly)
Returns the value of attribute flavors.
179 180 181 |
# File 'lib/vim-flavor.rb', line 179 def flavors @flavors end |
Instance Method Details
#eval_flavorfile(flavorfile_path) ⇒ Object
190 191 192 193 194 195 196 197 |
# File 'lib/vim-flavor.rb', line 190 def eval_flavorfile(flavorfile_path) content = File.open(flavorfile_path, 'rb') do |f| f.read() end interpret do instance_eval(content) end end |
#flavor(repo_name, *args) ⇒ Object
213 214 215 216 217 218 219 220 221 222 223 224 225 |
# File 'lib/vim-flavor.rb', line 213 def flavor(repo_name, *args) = Hash === args.last ? args.pop : {} [:groups] ||= [] version_contraint = VersionConstraint.new(args.last || '>= 0') f = Flavor.new() f.repo_name = repo_name f.repo_uri = repo_uri_from_repo_name(repo_name) f.version_contraint = version_contraint f.groups = @default_groups + [:groups] @flavors[f.repo_uri] = f end |
#group(*group_names, &block) ⇒ Object
227 228 229 230 231 232 233 234 |
# File 'lib/vim-flavor.rb', line 227 def group(*group_names, &block) @default_groups.concat(group_names) yield ensure group_names.each do @default_groups.pop() end end |
#interpret(&block) ⇒ Object
186 187 188 |
# File 'lib/vim-flavor.rb', line 186 def interpret(&block) instance_eval(&block) end |
#repo_uri_from_repo_name(repo_name) ⇒ Object
199 200 201 202 203 204 205 206 207 208 209 210 211 |
# File 'lib/vim-flavor.rb', line 199 def repo_uri_from_repo_name(repo_name) if /^([^\/]+)$/.match(repo_name) then m = Regexp.last_match "git://github.com/vim-scripts/#{m[1]}.git" elsif /^([A-Za-z0-9_-]+)\/(.*)$/.match(repo_name) then m = Regexp.last_match "git://github.com/#{m[1]}/#{m[2]}.git" elsif /^[a-z]+:\/\/.*$/.match(repo_name) then repo_name else raise "repo_name is written in invalid format: #{repo_name.inspect}" end end |