Class: GemButler
- Inherits:
-
Object
- Object
- GemButler
- Defined in:
- lib/gem_butler.rb
Instance Attribute Summary collapse
-
#base_path ⇒ Object
Returns the value of attribute base_path.
- #excluded_folders ⇒ Object
- #excluded_names ⇒ Object
- #include_only_folders ⇒ Object
- #include_only_names ⇒ Object
- #selected_names ⇒ Object
Instance Method Summary collapse
- #after_exclude ⇒ Object
- #after_exclude_folders ⇒ Object
- #exclude(options = {}) ⇒ Object
- #exclude_folders_list ⇒ Object
- #exclude_list ⇒ Object
- #filtered ⇒ Object
- #folder_filtered ⇒ Object
- #gemfile_names(mode = :included) ⇒ Object
- #gemfile_paths ⇒ Object
- #gemfiles ⇒ Object
- #gemfiles_path ⇒ Object
- #include_only(options = {}) ⇒ Object
-
#initialize(path) ⇒ GemButler
constructor
A new instance of GemButler.
- #name_filtered ⇒ Object
- #only_included ⇒ Object
- #only_included? ⇒ Boolean
- #only_included_folders ⇒ Object
- #only_included_folders? ⇒ Boolean
- #select(*names) ⇒ Object
- #select_list ⇒ Object
- #selected ⇒ Object
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_path ⇒ Object
Returns the value of attribute base_path.
2 3 4 |
# File 'lib/gem_butler.rb', line 2 def base_path @base_path end |
#excluded_folders ⇒ Object
122 123 124 |
# File 'lib/gem_butler.rb', line 122 def excluded_folders @excluded_folders ||= [] end |
#excluded_names ⇒ Object
114 115 116 |
# File 'lib/gem_butler.rb', line 114 def excluded_names @excluded_names ||= [] end |
#include_only_folders ⇒ Object
118 119 120 |
# File 'lib/gem_butler.rb', line 118 def include_only_folders @include_only_folders ||= [] end |
#include_only_names ⇒ Object
110 111 112 |
# File 'lib/gem_butler.rb', line 110 def include_only_names @include_only_names ||= [] end |
#selected_names ⇒ Object
142 143 144 |
# File 'lib/gem_butler.rb', line 142 def selected_names @selected_names ||= [] end |
Instance Method Details
#after_exclude ⇒ Object
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_folders ⇒ Object
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 = {} self.excluded_names = .delete(:names) self.excluded_folders = .delete(:folders) end |
#exclude_folders_list ⇒ Object
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_list ⇒ Object
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 |
#filtered ⇒ Object
30 31 32 |
# File 'lib/gem_butler.rb', line 30 def filtered selected + (name_filtered & folder_filtered) end |
#folder_filtered ⇒ Object
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_paths ⇒ Object
26 27 28 |
# File 'lib/gem_butler.rb', line 26 def gemfile_paths @gemfile_paths ||= gemfiles.map(&:to_s) end |
#gemfiles ⇒ Object
12 13 14 |
# File 'lib/gem_butler.rb', line 12 def gemfiles @gemfiles ||= Dir.glob File.join(gemfiles_path, '**', '*.gemfile') end |
#gemfiles_path ⇒ Object
96 97 98 |
# File 'lib/gem_butler.rb', line 96 def gemfiles_path File.(base_path, __FILE__) end |
#include_only(options = {}) ⇒ Object
100 101 102 103 |
# File 'lib/gem_butler.rb', line 100 def include_only = {} self.include_only_names = .delete(:names) self.include_only_folders = .delete(:folders) end |
#name_filtered ⇒ Object
34 35 36 37 |
# File 'lib/gem_butler.rb', line 34 def name_filtered return only_included if only_included? after_exclude end |
#only_included ⇒ Object
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
67 68 69 |
# File 'lib/gem_butler.rb', line 67 def only_included? !only_included.empty? end |
#only_included_folders ⇒ Object
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
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_list ⇒ Object
134 135 136 |
# File 'lib/gem_butler.rb', line 134 def select_list [selected_names].flatten - [excluded_names].flatten end |
#selected ⇒ Object
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 |