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.



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

def initialize hash
  raise "Abstract class" if self.class == Project
  raise "expected hash" unless hash.is_a? Hash

  hash = hash.keys.to_h do |key|
    [key.to_s, hash[key]]
  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?
      # :nocov:
      raise "invalid attribute(s): #{invalid_attrib.join(', ')}"
      # :nocov:
    end
  end

  path = hash.delete('path')

  hash.each_pair do |key, value|
    send("#{key}=", value)
  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



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/externals/project.rb', line 17

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

.inherited(child) ⇒ Object



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

def self.inherited child
  super

  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
    #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"]
      end
    end
    Project.__send__(:define_method, "#{scm_name}_opts=") do |value|
      attributes[:"#{scm_name}_opts"] = 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],
            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



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

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



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

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

#attributesObject



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

def attributes
  @attributes ||= {}
end

#checkout(*args) ⇒ Object



104
105
106
# File 'lib/externals/project.rb', line 104

def checkout *args
  co(*args)
end

#export(*args) ⇒ Object



108
109
110
# File 'lib/externals/project.rb', line 108

def export *args
  ex(*args)
end

#extract_name(repository) ⇒ Object



112
113
114
115
116
# File 'lib/externals/project.rb', line 112

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

#main_project?Boolean

Returns:

  • (Boolean)


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

def main_project?
  path == '.'
end

#nameObject



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

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

#scmObject



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

def scm
  self.class.scm
end

#scm_optsObject



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

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

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

#scm_opts=(value) ⇒ Object



148
149
150
# File 'lib/externals/project.rb', line 148

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

#switch(_branch_name, _options = {}) ⇒ Object



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

def switch _branch_name, _options = {}
  # :nocov:
  raise "subclass responsibility"
  # :nocov:
end

#update_ignore(path) ⇒ Object



98
99
100
101
102
# File 'lib/externals/project.rb', line 98

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