Class: Externals::Project
- Inherits:
-
Object
- Object
- Externals::Project
- Extended by:
- FileUtils
- Includes:
- FileUtils
- Defined in:
- lib/externals/project.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#parent ⇒ Object
Returns the value of attribute parent.
Class Method Summary collapse
- .attr_attr_accessor(*names) ⇒ Object
- .default_branch ⇒ Object
- .inherited(child) ⇒ Object
- .scm ⇒ Object
Instance Method Summary collapse
-
#assert_e_dne_i_ni(assert, exists, doesnt = [], ignored = exists, notignored = []) ⇒ Object
test helper method.
- #attributes ⇒ Object
- #checkout(*args) ⇒ Object
- #default_branch ⇒ Object
- #export(*args) ⇒ Object
- #extract_name(repository) ⇒ Object
-
#initialize(hash) ⇒ Project
constructor
A new instance of Project.
- #main_project? ⇒ Boolean
- #name ⇒ Object
- #scm ⇒ Object
- #scm_opts ⇒ Object
- #scm_opts=(value) ⇒ Object
- #switch(branch_name, options = {}) ⇒ Object
- #update_ignore(path) ⇒ Object
Constructor Details
#initialize(hash) ⇒ Project
Returns a new instance of Project.
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/externals/project.rb', line 63 def initialize hash raise "Abstract class" if self.class == Project raise "expected hash" unless hash.is_a? Hash hash = hash.keys.inject({}) do |new_hash, key| new_hash[key.to_s] = hash[key] new_hash end invalid_attrib = hash.keys - Externals::VALID_ATTRIB if !invalid_attrib.empty? invalid_attrib.reject! do |attribute| attribute =~ /^\w+_opts(_(#{OPTS_SUFFIXES.join("|")}))?/ end if !invalid_attrib.empty? raise "invalid attribute(s): #{invalid_attrib.join(', ')}" end end path = hash.delete('path') hash.keys.each do |key| send("#{key}=", hash[key]) end if path && !path.is_a?(String) path = path.default_path(name) end self.path = path end |
Instance Attribute Details
#parent ⇒ Object
Returns the value of attribute parent.
12 13 14 |
# File 'lib/externals/project.rb', line 12 def parent @parent end |
Class Method Details
.attr_attr_accessor(*names) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/externals/project.rb', line 16 def self.attr_attr_accessor *names names = [names].flatten names.each do |name| define_method "#{name}=" do |value| attributes[name.to_sym] = value end next if name == "name" || name == "scm" define_method name do attributes[name.to_sym] end end end |
.default_branch ⇒ Object
51 52 53 |
# File 'lib/externals/project.rb', line 51 def self.default_branch raise "subclass responsibility" end |
.inherited(child) ⇒ Object
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 |
# File 'lib/externals/project.rb', line 177 def self.inherited child child.class_eval do def self.scm @scm ||= /^([^:]*::)*([^:]+)Project$/.match(name)[2].downcase end #create the <scm_name>_opts_co/ex/st/up and <scm_opts>_opts setting #such as svn_opts and svn_opts_co from the main project (stored #in the parrent attribute.) raise unless scm && scm != "" #first we create global <scm_name>_opts accessors that will apply to all #of the suffixed versions (<scm_name>_opts_co) as well as the project #specific ones. (scm_opts, scm_opts_co, etc) scm_name = scm Project.__send__(:define_method, "#{scm_name}_opts_raw") do attributes[name.to_sym] end #global settings are fetched from the parent project. Project.__send__(:define_method, "#{scm_name}_opts") do if parent parent.__send__("#{scm_name}_opts") else attributes["#{scm_name}_opts".to_sym] end end Project.__send__(:define_method, "#{scm_name}_opts=") do |value| attributes["#{scm_name}_opts".to_sym] = value end #now we create the suffixed version of the global settings. OPTS_SUFFIXES.map do |suffix| "#{scm_name}_opts_#{suffix}" end.each do |name| #defer to the parent project for these global settings Project.__send__(:define_method, name) do if parent parent.__send__(name) else values = [ attributes[name.to_sym], self.send("#{scm_name}_opts") ].compact if !values.empty? values.join(" ") end end end Project.__send__(:define_method, "#{name}=") do |value| attributes[name.to_sym] = value end end end end |
.scm ⇒ Object
41 42 43 44 45 |
# File 'lib/externals/project.rb', line 41 def self.scm if self == Project raise "subclass responsibility" end end |
Instance Method Details
#assert_e_dne_i_ni(assert, exists, doesnt = [], ignored = exists, notignored = []) ⇒ Object
test helper method
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/externals/project.rb', line 122 def assert_e_dne_i_ni assert, exists, doesnt = [], ignored = exists, notignored = [] ignored.each do |proj| assert.call(ignore_text("vendor/plugins/#{proj}") =~ /#{proj}$/) end notignored.each do |proj| assert.call(ignore_text("vendor/plugins/#{proj}") !~ /#{proj}$/) end exists.each do |proj| assert.call File.exist?(File.join('vendor', 'plugins', proj, 'lib')) end doesnt.each do |proj| assert.call !File.exist?(File.join('vendor', 'plugins', proj, 'lib')) end end |
#attributes ⇒ Object
31 32 33 |
# File 'lib/externals/project.rb', line 31 def attributes @attributes ||= {} end |
#checkout(*args) ⇒ Object
107 108 109 |
# File 'lib/externals/project.rb', line 107 def checkout *args co(*args) end |
#default_branch ⇒ Object
55 56 57 |
# File 'lib/externals/project.rb', line 55 def default_branch self.class.default_branch end |
#export(*args) ⇒ Object
111 112 113 |
# File 'lib/externals/project.rb', line 111 def export *args ex(*args) end |
#extract_name(repository) ⇒ Object
115 116 117 118 119 |
# File 'lib/externals/project.rb', line 115 def extract_name repository if repository =~ /\/([\w-]+)(?:\.git)?$/ $1 end end |
#main_project? ⇒ Boolean
37 38 39 |
# File 'lib/externals/project.rb', line 37 def main_project? path == '.' end |
#name ⇒ Object
34 35 36 |
# File 'lib/externals/project.rb', line 34 def name attributes[:name] || extract_name(repository) end |
#scm ⇒ Object
47 48 49 |
# File 'lib/externals/project.rb', line 47 def scm self.class.scm end |
#scm_opts ⇒ Object
140 141 142 143 144 145 146 147 148 149 |
# File 'lib/externals/project.rb', line 140 def scm_opts values = [ attributes[:scm_opts], send("#{scm}_opts") ].compact if !values.empty? values.join(" ") end end |
#scm_opts=(value) ⇒ Object
151 152 153 |
# File 'lib/externals/project.rb', line 151 def scm_opts= value attributes[:scm_opts] = value end |
#switch(branch_name, options = {}) ⇒ Object
59 60 61 |
# File 'lib/externals/project.rb', line 59 def switch branch_name, = {} raise "subclass responsibility" end |
#update_ignore(path) ⇒ Object
101 102 103 104 105 |
# File 'lib/externals/project.rb', line 101 def update_ignore path if !ignore_contains?(path) append_ignore path end end |