Class: RC::ConfigFilter

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/rc/config_filter.rb

Overview

To be quite honest I have forgotten the purpose of this class and it is no longer being used, so it should be deleted. But I am holding off a bit, in case I recall why it was here, in order to be sure.

Instance Method Summary collapse

Constructor Details

#initialize(configuration, criteria = {}) ⇒ ConfigFilter

Initialize new ConfigFilter.

Parameters:

  • configuration (Array<Config>)

    List if Config instances.



18
19
20
21
22
23
24
25
26
27
# File 'lib/rc/config_filter.rb', line 18

def initialize(configuration, criteria={})
  @configuration = configuration
  @criteria      = criteria

  @list = []

  configuration.each do |c|
    @list << c if c.match?(criteria)
  end
end

Instance Method Details

#[](subset) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
# File 'lib/rc/config_filter.rb', line 53

def [](subset)
  return method_missing(:[]) if profile
  if tool
    criteria = @criteria.dup
    criteria[:profile] = subset
  else
    criteria = @criteria.dup
    criteria[:tool] = subset
  end
  self.class.new(@configuration, criteria)
end

#call(*args) ⇒ Object

Call each config.



84
85
86
87
88
89
90
# File 'lib/rc/config_filter.rb', line 84

def call(*args)
  @list.each do |c|
    if c.profile?(RC.current_profile)
      c.call(*args)
    end
  end
end

#each(&block) ⇒ Object



68
69
70
71
72
# File 'lib/rc/config_filter.rb', line 68

def each(&block)
  @list.each do
    block
  end
end

#profileObject



39
40
41
# File 'lib/rc/config_filter.rb', line 39

def profile
  @criteria[:profile]
end

#profilesObject

Returns list of profiles.



46
47
48
# File 'lib/rc/config_filter.rb', line 46

def profiles
  @list.map{ |c| c.profile }
end

#sizeObject



77
78
79
# File 'lib/rc/config_filter.rb', line 77

def size
  @list.size
end

#to_proc(exec = false) ⇒ Object

Convert to Proc.



95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/rc/config_filter.rb', line 95

def to_proc(exec=false)
  list = @list
  if exec
    Proc.new do |*args|
      list.each{ |c| instance_exec(*args, &c) }
    end
  else
    Proc.new do |*args|
      list.each{ |c| c.call(*args) }
    end
  end
end

#toolObject



32
33
34
# File 'lib/rc/config_filter.rb', line 32

def tool
  @criteria[:tool]
end