Class: CfScript::AppList

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Enumerable
Defined in:
lib/cf_script/object/app_list.rb

Instance Method Summary collapse

Constructor Details

#initialize(list = []) ⇒ AppList

Returns a new instance of AppList.



5
6
7
# File 'lib/cf_script/object/app_list.rb', line 5

def initialize(list = [])
  @list = list
end

Instance Method Details

#==(other) ⇒ Object



15
16
17
# File 'lib/cf_script/object/app_list.rb', line 15

def ==(other)
  names == other.names
end

#each_name(&block) ⇒ Object



19
20
21
# File 'lib/cf_script/object/app_list.rb', line 19

def each_name(&block)
  names.each { |name| yield(name) }
end

#namesObject



11
12
13
# File 'lib/cf_script/object/app_list.rb', line 11

def names
  @list.map(&:name)
end

#select!(options) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/cf_script/object/app_list.rb', line 23

def select!(options)
  if options[:matching]
    @list.select! { |app_info| app_info.name =~ /#{options[:matching]}/ }
  end

  if options[:starting_with]
    @list.reject! { |app_info| app_info.name !~ /\A#{options[:starting_with]}/ }
  end

  if options[:ending_with]
    @list.reject! { |app_info| app_info.name !~ /#{options[:ending_with]}\z/ }
  end

  if options[:state]
    @list.reject! { |app_info| app_info.requested_state !~ /\A#{options[:state]}\z/ }
  end
end