Class: Ore::Project

Inherits:
Object
  • Object
show all
Includes:
Checks, Inferences, Naming, Paths, RubyGems, Settings
Defined in:
lib/ore/project.rb

Overview

Combines the metadata from the gemspec.yml file and the inferred information from the project directory.

Constant Summary collapse

@@metadata_file =

The project metadata file

'gemspec.yml'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from RubyGems

#to_gem, #to_gemspec

Methods included from Paths

#bin_dir, #directory?, #each_path, #file?, #glob, #lib_dir, #lib_directory?, #lib_file?, #lib_path, #path, #pkg_dir, #pkg_file

Methods included from Naming

#module_of, #modules_of, #names_in, #namespace_dirs_of, #namespace_of, #namespace_path_of, #underscore

Methods included from Settings

#set_authors!, #set_date!, #set_default_executable!, #set_dependencies!, #set_development_dependencies!, #set_emails!, #set_executables!, #set_extra_doc_files!, #set_files!, #set_license!, #set_require_paths!, #set_requirements!, #set_runtime_dependencies!, #set_test_files!, #set_version!

Methods included from Inferences

#infer_date!, #infer_default_executable!, #infer_documentation!, #infer_executables!, #infer_extra_doc_files!, #infer_files!, #infer_name!, #infer_namespace!, #infer_project_files!, #infer_require_paths!, #infer_required_rubygems_version!, #infer_scm!, #infer_test_files!, #infer_version!

Methods included from Checks

#check_directory, #check_executable, #check_file, #check_readable

Constructor Details

#initialize(root = Dir.pwd) ⇒ Project

Creates a new Ore::Project.

Parameters:

  • root (String) (defaults to: Dir.pwd)

    The root directory of the project.



129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
# File 'lib/ore/project.rb', line 129

def initialize(root=Dir.pwd)
  @root = Pathname.new(root).expand_path

  unless @root.directory?
    raise(ProjectNotFound,"#{@root} is not a directory")
  end

  infer_scm!
  infer_project_files!

   = @root.join(@@metadata_file)

  unless .file?
    raise(ProjectNotFound,"#{@root} does not contain #{@@metadata_file}")
  end

   = YAML.load_file()

  unless .kind_of?(Hash)
    raise(InvalidMetadata,"#{} did not contain valid metadata")
  end

  if ['name']
    @name = ['name'].to_s
  else
    infer_name!
  end

  # infer the namespace from the project name
  infer_namespace!

  if ['version']
    set_version! ['version']
  else
    infer_version!
  end

  @summary = (['summary'] || ['description'])
  @description = (['description'] || ['summary'])

  @licenses = []

  if ['license']
    set_license!(['license'])
  end

  @authors = []

  if ['authors']
    set_authors! ['authors']
  end

  @homepage = ['homepage']
  @emails = []
  
  if ['email']
    set_emails! ['email']
  end

  if ['date']
    set_date! ['date']
  else
    infer_date!
  end

  @document = DocumentFile.find(self)

  @require_paths = []

  if ['require_paths']
    set_require_paths! ['require_paths']
  else
    infer_require_paths!
  end

  @executables = []

  if ['executables']
    set_executables! ['executables']
  else
    infer_executables!
  end

  @default_executable = nil

  if ['default_executable']
    set_default_executable! ['default_executable']
  else
    infer_default_executable!
  end

  if ['has_yard']
    @documentation = :yard
  elsif .has_key?('has_rdoc')
    @documentation = if ['has_rdoc']
                       :rdoc
                     end
  else
    infer_documentation!
  end

  @extra_doc_files = []

  if ['extra_doc_files']
    set_extra_doc_files! ['extra_doc_files']
  else
    infer_extra_doc_files!
  end

  @files = []

  if ['files']
    set_files! ['files']
  else
    infer_files!
  end

  @test_files = []

  if ['test_files']
    set_test_files! ['test_files']
  else
    infer_test_files!
  end

  if ['post_install_message']
    @post_install_message = ['post_install_message']
  end

  @requirements = []

  if ['requirements']
    set_requirements! ['requirements']
  end

  if ['required_ruby_version']
    @required_ruby_version = ['required_ruby_version']
  end

  if ['required_rubygems_version']
    @required_rubygems_version = ['required_rubygems_version']
  else
    infer_required_rubygems_version!
  end

  @dependencies = []

  if ['dependencies']
    set_dependencies! ['dependencies']
  end

  @runtime_dependencies = []

  if ['runtime_dependencies']
    set_runtime_dependencies! ['runtime_dependencies']
  end

  @development_dependencies = []

  if ['development_dependencies']
    set_development_dependencies! ['development_dependencies']
  end
end

Instance Attribute Details

#authorsObject (readonly)

The authors of the project



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

def authors
  @authors
end

#dateObject (readonly)

The build date for any project gems



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

def date
  @date
end

#default_executableObject (readonly)

The default executable



88
89
90
# File 'lib/ore/project.rb', line 88

def default_executable
  @default_executable
end

#dependenciesObject (readonly)

The dependencies of the project



112
113
114
# File 'lib/ore/project.rb', line 112

def dependencies
  @dependencies
end

#descriptionObject (readonly)

The project description



61
62
63
# File 'lib/ore/project.rb', line 61

def description
  @description
end

#development_dependenciesObject (readonly)

The development-dependencies of the project



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

def development_dependencies
  @development_dependencies
end

#documentObject (readonly)

The parsed .document file



79
80
81
# File 'lib/ore/project.rb', line 79

def document
  @document
end

#documentationObject (readonly)

The documentation of the project



91
92
93
# File 'lib/ore/project.rb', line 91

def documentation
  @documentation
end

#emailsObject (readonly)

The email contacts for the project



73
74
75
# File 'lib/ore/project.rb', line 73

def emails
  @emails
end

#executablesObject (readonly)

The names of the executable scripts



85
86
87
# File 'lib/ore/project.rb', line 85

def executables
  @executables
end

#extra_doc_filesObject (readonly)

Any extra files to include in the project documentation



94
95
96
# File 'lib/ore/project.rb', line 94

def extra_doc_files
  @extra_doc_files
end

#filesObject (readonly)

The files of the project



97
98
99
# File 'lib/ore/project.rb', line 97

def files
  @files
end

#homepageObject (readonly)

The homepage for the project



70
71
72
# File 'lib/ore/project.rb', line 70

def homepage
  @homepage
end

#licensesObject (readonly)

The licenses of the project



64
65
66
# File 'lib/ore/project.rb', line 64

def licenses
  @licenses
end

#nameObject (readonly)

The name of the project



52
53
54
# File 'lib/ore/project.rb', line 52

def name
  @name
end

#namespaceObject (readonly)

The fully-qualified namespace of the project



43
44
45
# File 'lib/ore/project.rb', line 43

def namespace
  @namespace
end

#namespace_dirObject (readonly)

The directory contain the project code.



49
50
51
# File 'lib/ore/project.rb', line 49

def namespace_dir
  @namespace_dir
end

#namespace_modulesObject (readonly)

The inferred namespace modules of the project



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

def namespace_modules
  @namespace_modules
end

#post_install_messageObject (readonly)

The post-installation message



121
122
123
# File 'lib/ore/project.rb', line 121

def post_install_message
  @post_install_message
end

#project_filesObject (readonly)

The files of the project



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

def project_files
  @project_files
end

#require_pathsObject (readonly)

The directories to search within the project when requiring files



82
83
84
# File 'lib/ore/project.rb', line 82

def require_paths
  @require_paths
end

#required_ruby_versionObject (readonly)

The version of Ruby required by the project



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

def required_ruby_version
  @required_ruby_version
end

#required_rubygems_versionObject (readonly)

The version of RubyGems required by the project



109
110
111
# File 'lib/ore/project.rb', line 109

def required_rubygems_version
  @required_rubygems_version
end

#requirementsObject (readonly)

Any external requirements needed by the project



103
104
105
# File 'lib/ore/project.rb', line 103

def requirements
  @requirements
end

#rootObject (readonly)

The root directory of the project



34
35
36
# File 'lib/ore/project.rb', line 34

def root
  @root
end

#runtime_dependenciesObject (readonly)

The runtime-dependencies of the project



115
116
117
# File 'lib/ore/project.rb', line 115

def runtime_dependencies
  @runtime_dependencies
end

#scmObject (readonly)

The SCM which the project is currently under



37
38
39
# File 'lib/ore/project.rb', line 37

def scm
  @scm
end

#summaryObject (readonly)

The project summary



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

def summary
  @summary
end

#test_filesObject (readonly)

The test files for the project



100
101
102
# File 'lib/ore/project.rb', line 100

def test_files
  @test_files
end

#versionObject (readonly)

The version of the project



55
56
57
# File 'lib/ore/project.rb', line 55

def version
  @version
end

Class Method Details

.find(dir = Dir.pwd) ⇒ Project

Finds the project metadata file and creates a new Ore::Project object.

Parameters:

  • dir (String) (defaults to: Dir.pwd)

    (Dir.pwd) The directory to start searching upward from.

Returns:

Raises:



305
306
307
308
309
310
311
# File 'lib/ore/project.rb', line 305

def self.find(dir=Dir.pwd)
  Pathname.new(dir).ascend do |root|
    return self.new(root) if root.join(@@metadata_file).file?
  end

  raise(ProjectNotFound,"could not find #{@@metadata_file}")
end

Instance Method Details

#add_executable(name) ⇒ Object (protected)

Adds an executable to the project.

Parameters:

  • name (String)

    The name of the executable.



463
464
465
466
467
# File 'lib/ore/project.rb', line 463

def add_executable(name)
  path = File.join(@@bin_dir,name)

  check_executable(path) { |exe| @executables << exe }
end

#add_extra_doc_file(path) ⇒ Object (protected)

Adds an extra documentation file to the project.

Parameters:

  • path (String)

    The path to the file, relative to the project.



475
476
477
# File 'lib/ore/project.rb', line 475

def add_extra_doc_file(path)
  check_file(path) { |file| @extra_doc_files << file }
end

#add_file(path) ⇒ Object (protected)

Adds a file to the project.

Parameters:

  • path (String)

    The path to the file, relative to the project.



485
486
487
# File 'lib/ore/project.rb', line 485

def add_file(path)
  check_file(path) { |file| @files << file }
end

#add_require_path(path) ⇒ Object (protected)

Adds a require-path to the project.

Parameters:

  • path (String)

    A directory path relative to the project.



453
454
455
# File 'lib/ore/project.rb', line 453

def add_require_path(path)
  check_directory(path) { |dir| @require_paths << dir }
end

#add_test_file(path) ⇒ Object (protected)

Adds a testing-file to the project.

Parameters:

  • path (String)

    The path to the testing-file, relative to the project.



495
496
497
# File 'lib/ore/project.rb', line 495

def add_test_file(path)
  check_file(path) { |file| @test_files << file }
end

#build!(package = :gem) ⇒ Pathname

Builds a gem for the project.

Parameters:

  • package (Symbol) (defaults to: :gem)

    The type of package to build.

Returns:

  • (Pathname)

    The path to the built gem file within the pkg/ directory.

Raises:

  • (ArgumentError)

    The given package type is not supported.



427
428
429
430
431
432
433
# File 'lib/ore/project.rb', line 427

def build!(package=:gem)
  if package == :gem
    to_gem
  else
    raise(ArgumentError,"unsupported package type #{package}")
  end
end

#bundled?Boolean

Determines whether the project has been bundled using Bundler.

Returns:

  • (Boolean)

    Specifies whether the project has been bundled.



387
388
389
# File 'lib/ore/project.rb', line 387

def bundled?
  file?('Gemfile.lock')
end

#bundler?Boolean

Determines whether the project uses Bundler.

Returns:

  • (Boolean)

    Specifies whether the project uses Bundler.



377
378
379
# File 'lib/ore/project.rb', line 377

def bundler?
  file?('Gemfile')
end

#emailString?

The primary email address of the project.

Returns:

  • (String, nil)

    The primary email address for the project.

Since:

  • 0.1.3



354
355
356
# File 'lib/ore/project.rb', line 354

def email
  @emails.first
end

#has_rdocBoolean Also known as: has_rdoc?

Determines if the project contains RDoc documentation.

Returns:

  • (Boolean)

    Specifies whether the project has RDoc documentation.



397
398
399
# File 'lib/ore/project.rb', line 397

def has_rdoc
  @documentation == :rdoc
end

#has_yardBoolean Also known as: has_yard?

Determines if the project contains YARD documentation.

Returns:

  • (Boolean)

    Specifies whether the project has YARD documentation.



409
410
411
# File 'lib/ore/project.rb', line 409

def has_yard
  @documentation == :yard
end

#licenseString?

The primary license of the project.

Returns:

  • (String, nil)

    The primary license for the project.



342
343
344
# File 'lib/ore/project.rb', line 342

def license
  @licenses.first
end

#rvm?Boolean

Determines whether the project prefers using RVM.

Returns:

  • (Boolean)

    Specifies whether the project prefers being developed under RVM.

Since:

  • 0.1.2



367
368
369
# File 'lib/ore/project.rb', line 367

def rvm?
  file?('.rvmrc')
end

#warn(*messages) ⇒ Object (protected)

Prints multiple warning messages.

Parameters:

  • messages (Array)

    The messages to print.



443
444
445
# File 'lib/ore/project.rb', line 443

def warn(*messages)
  messages.each { |mesg| STDERR.puts("WARNING: #{mesg}") }
end

#within(sub_dir = nil) { ... } ⇒ Object

Executes code within the project.

Parameters:

  • sub_dir (String) (defaults to: nil)

    An optional sub-directory within the project to execute from.

Yields:

  • [] The given block will be called once the current working-directory has been switched. Once the block finishes executing, the current working-directory will be switched back.

See Also:



326
327
328
329
330
331
332
333
334
# File 'lib/ore/project.rb', line 326

def within(sub_dir=nil,&block)
  dir = if sub_dir
          @root.join(sub_dir)
        else
          @root
        end

  Dir.chdir(dir,&block)
end