Class: GemButler

Inherits:
Object
  • Object
show all
Defined in:
lib/gem_butler.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ GemButler

Returns a new instance of GemButler.



8
9
10
# File 'lib/gem_butler.rb', line 8

def initialize path
  @base_path = path
end

Instance Attribute Details

#base_pathObject

Returns the value of attribute base_path.



2
3
4
# File 'lib/gem_butler.rb', line 2

def base_path
  @base_path
end

#excluded_foldersObject



122
123
124
# File 'lib/gem_butler.rb', line 122

def excluded_folders
  @excluded_folders ||= []
end

#excluded_namesObject



114
115
116
# File 'lib/gem_butler.rb', line 114

def excluded_names
  @excluded_names ||= []
end

#include_only_foldersObject



118
119
120
# File 'lib/gem_butler.rb', line 118

def include_only_folders
  @include_only_folders ||= []    
end

#include_only_namesObject



110
111
112
# File 'lib/gem_butler.rb', line 110

def include_only_names
  @include_only_names ||= []    
end

#selected_namesObject



142
143
144
# File 'lib/gem_butler.rb', line 142

def selected_names
  @selected_names ||= []
end

Instance Method Details

#after_excludeObject



39
40
41
42
43
44
# File 'lib/gem_butler.rb', line 39

def after_exclude
  return [] if !excluded_names
  @after_excluded ||= begin      
    gemfile_paths - exclude_list.flatten
  end
end

#after_exclude_foldersObject



60
61
62
63
64
65
# File 'lib/gem_butler.rb', line 60

def after_exclude_folders
  return [] if !excluded_folders
  @after_excluded_folders ||= begin      
    gemfile_paths - exclude_folders_list.flatten
  end
end

#exclude(options = {}) ⇒ Object



105
106
107
108
# File 'lib/gem_butler.rb', line 105

def exclude options = {}
  self.excluded_names   = options.delete(:names)
  self.excluded_folders = options.delete(:folders)
end

#exclude_folders_listObject



53
54
55
56
57
58
# File 'lib/gem_butler.rb', line 53

def exclude_folders_list
  @exclude_folders_list ||= [excluded_folders].flatten.inject([]) do |res, folder|
    res += gemfile_paths.grep(/#{folder}\//i)
    res
  end
end

#exclude_listObject



46
47
48
49
50
51
# File 'lib/gem_butler.rb', line 46

def exclude_list
  @exclude_list ||= [excluded_names].flatten.inject([]) do |res, gemfile|
    res += gemfile_paths.grep(/#{prepare gemfile}\.gemfile$/i)
    res
  end
end

#filteredObject



30
31
32
# File 'lib/gem_butler.rb', line 30

def filtered
  selected + (name_filtered & folder_filtered)
end

#folder_filteredObject



71
72
73
74
# File 'lib/gem_butler.rb', line 71

def folder_filtered
  return only_included_folders if only_included_folders?
  after_exclude_folders
end

#gemfile_names(mode = :included) ⇒ Object



16
17
18
19
20
21
22
23
24
# File 'lib/gem_butler.rb', line 16

def gemfile_names mode = :included
  list = case mode
  when :included
    filtered
  else
    gemfiles
  end
  list.map {|gemfile| gemfile.match(/\/(\w+)\.\w+$/i)[1] }
end

#gemfile_pathsObject



26
27
28
# File 'lib/gem_butler.rb', line 26

def gemfile_paths
  @gemfile_paths ||= gemfiles.map(&:to_s)
end

#gemfilesObject



12
13
14
# File 'lib/gem_butler.rb', line 12

def gemfiles
  @gemfiles ||= Dir.glob File.join(gemfiles_path, '**', '*.gemfile')
end

#gemfiles_pathObject



96
97
98
# File 'lib/gem_butler.rb', line 96

def gemfiles_path
  File.expand_path(base_path, __FILE__)
end

#include_only(options = {}) ⇒ Object



100
101
102
103
# File 'lib/gem_butler.rb', line 100

def include_only options = {}
  self.include_only_names   = options.delete(:names)
  self.include_only_folders = options.delete(:folders)
end

#name_filteredObject



34
35
36
37
# File 'lib/gem_butler.rb', line 34

def name_filtered
  return only_included if only_included?
  after_exclude
end

#only_includedObject



88
89
90
91
92
93
94
# File 'lib/gem_butler.rb', line 88

def only_included
  return [] if !include_only_names
  @only_included ||= [include_only_names].flatten.inject([]) do |res, gemfile|
    res += gemfile_paths.grep(/#{prepare gemfile}\.gemfile$/i)
    res
  end
end

#only_included?Boolean

Returns:

  • (Boolean)


67
68
69
# File 'lib/gem_butler.rb', line 67

def only_included?
  !only_included.empty?
end

#only_included_foldersObject



80
81
82
83
84
85
86
# File 'lib/gem_butler.rb', line 80

def only_included_folders
  return [] if !include_only_folders
  @only_included_folders ||= [include_only_folders].flatten.inject([]) do |res, folder|
    res += gemfile_paths.grep(/#{folder}\//i)
    res
  end
end

#only_included_folders?Boolean

Returns:

  • (Boolean)


76
77
78
# File 'lib/gem_butler.rb', line 76

def only_included_folders?
  !only_included_folders.empty?
end

#select(*names) ⇒ Object



138
139
140
# File 'lib/gem_butler.rb', line 138

def select *names
  self.selected_names = names.flatten.compact.uniq
end

#select_listObject



134
135
136
# File 'lib/gem_butler.rb', line 134

def select_list
  [selected_names].flatten - [excluded_names].flatten
end

#selectedObject



126
127
128
129
130
131
132
# File 'lib/gem_butler.rb', line 126

def selected
  return [] if !include_only_folders
  @selected ||= [select_list].flatten.inject([]) do |res, gemfile|
    res += gemfile_paths.grep(/#{prepare gemfile}\.gemfile$/i)
    res
  end        
end