Class: Externals::Project

Inherits:
Object
  • Object
show all
Extended by:
FileUtils
Includes:
FileUtils
Defined in:
lib/externals/project.rb

Direct Known Subclasses

GitProject, SvnProject

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ Project

Returns a new instance of Project.



62
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
# File 'lib/externals/project.rb', line 62

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

#parentObject

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
# File 'lib/externals/project.rb', line 16

def self.attr_attr_accessor *names
  names = [names].flatten
  names.each do |name|
    define_method name do
      attributes[name.to_sym]
    end
    define_method "#{name}=" do |value|
      attributes[name.to_sym] = value
    end
  end
end

.default_branchObject



50
51
52
# File 'lib/externals/project.rb', line 50

def self.default_branch
  raise "subclass responsibility"
end

.inherited(child) ⇒ Object



176
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
# File 'lib/externals/project.rb', line 176

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|
      name = "#{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

.scmObject



40
41
42
43
44
# File 'lib/externals/project.rb', line 40

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



121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/externals/project.rb', line 121

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.exists?(File.join('vendor', 'plugins', proj, 'lib'))
  end

  doesnt.each do |proj|
    assert.call !File.exists?(File.join('vendor', 'plugins', proj, 'lib'))
  end
end

#attributesObject



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

def attributes
  @attributes ||= {}
end

#checkout(*args) ⇒ Object



106
107
108
# File 'lib/externals/project.rb', line 106

def checkout *args
  co(*args)
end

#default_branchObject



54
55
56
# File 'lib/externals/project.rb', line 54

def default_branch
  self.class.default_branch
end

#export(*args) ⇒ Object



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

def export *args
  ex(*args)
end

#extract_name(repository) ⇒ Object



114
115
116
117
118
# File 'lib/externals/project.rb', line 114

def extract_name repository
  if repository =~ /\/([\w_-]+)(?:\.git)?$/
    $1
  end
end

#main_project?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/externals/project.rb', line 36

def main_project?
  path == '.'
end

#nameObject



33
34
35
# File 'lib/externals/project.rb', line 33

def name
  attributes[:name] || extract_name(repository)
end

#scmObject



46
47
48
# File 'lib/externals/project.rb', line 46

def scm
  self.class.scm
end

#scm_optsObject



139
140
141
142
143
144
145
146
147
148
# File 'lib/externals/project.rb', line 139

def scm_opts
  values = [
    attributes[:scm_opts],
    send("#{scm}_opts")
  ].compact

  if !values.empty?
    values.join(" ")
  end
end

#scm_opts=(value) ⇒ Object



150
151
152
# File 'lib/externals/project.rb', line 150

def scm_opts= value
  attributes[:scm_opts] = value
end

#switch(branch_name, options = {}) ⇒ Object



58
59
60
# File 'lib/externals/project.rb', line 58

def switch branch_name, options = {}
  raise "subclass responsibility"
end

#update_ignore(path) ⇒ Object



100
101
102
103
104
# File 'lib/externals/project.rb', line 100

def update_ignore path
  if !ignore_contains?(path)
    append_ignore path
  end
end