Class: Vim::Flavor::FlavorFile

Inherits:
Object
  • Object
show all
Defined in:
lib/vim-flavor/flavorfile.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.load(flavorfile_path) ⇒ Object



23
24
25
26
27
# File 'lib/vim-flavor/flavorfile.rb', line 23

def self.load(flavorfile_path)
  ff = new()
  ff.load(flavorfile_path)
  ff
end

.load_or_new(flavorfile_path) ⇒ Object



17
18
19
20
21
# File 'lib/vim-flavor/flavorfile.rb', line 17

def self.load_or_new(flavorfile_path)
  ff = new()
  ff.load(flavorfile_path) if File.exists?(flavorfile_path)
  ff
end

Instance Method Details

#default_groupObject



13
14
15
# File 'lib/vim-flavor/flavorfile.rb', line 13

def default_group
  default_groups.last
end

#default_groupsObject



9
10
11
# File 'lib/vim-flavor/flavorfile.rb', line 9

def default_groups
  @default_groups ||= [:runtime]
end

#flavor(repo_name, version_constraint = nil, group: nil, branch: nil) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/vim-flavor/flavorfile.rb', line 36

def flavor(repo_name, version_constraint=nil, group: nil, branch: nil)
  if version_constraint and branch
    throw <<-"END"
Found an invalid declaration on #{repo_name}.
A version constraint '#{version_constraint}' and
a branch '#{branch}' are specified at the same time.
But a branch cannot be used with a version constraint.
    END
  end

  f = Flavor.new()
  f.repo_name = repo_name
  f.version_constraint = VersionConstraint.new(
    branch && "branch: #{branch}" ||
    version_constraint || '>= 0'
  )
  f.group = group || default_group
  flavor_table[f.repo_name] = f
end

#flavor_tableObject

repo_name -> flavor



5
6
7
# File 'lib/vim-flavor/flavorfile.rb', line 5

def flavor_table
  @flavor_table ||= {}
end

#group(group, &block) ⇒ Object



56
57
58
59
60
61
# File 'lib/vim-flavor/flavorfile.rb', line 56

def group(group, &block)
  default_groups.push(group)
  instance_eval &block
ensure
  default_groups.pop()
end

#load(flavorfile_path) ⇒ Object



29
30
31
32
33
34
# File 'lib/vim-flavor/flavorfile.rb', line 29

def load(flavorfile_path)
  instance_eval(
    File.open(flavorfile_path, 'r').read(),
    flavorfile_path
  )
end