ore 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (107) hide show
  1. data/.document +4 -0
  2. data/.rspec +1 -0
  3. data/.yardopts +1 -0
  4. data/ChangeLog.md +31 -0
  5. data/GemspecYML.md +252 -0
  6. data/LICENSE.txt +21 -0
  7. data/README.md +104 -0
  8. data/Rakefile +9 -0
  9. data/bin/mine +12 -0
  10. data/bin/ore +12 -0
  11. data/data/ore/templates/base/.document +3 -0
  12. data/data/ore/templates/base/.gitignore.erb +3 -0
  13. data/data/ore/templates/base/:name:.gemspec.erb +10 -0
  14. data/data/ore/templates/base/ChangeLog.md.erb +4 -0
  15. data/data/ore/templates/base/ChangeLog.rdoc.erb +4 -0
  16. data/data/ore/templates/base/ChangeLog.tt.erb +4 -0
  17. data/data/ore/templates/base/LICENSE.txt.erb +20 -0
  18. data/data/ore/templates/base/README.md.erb +42 -0
  19. data/data/ore/templates/base/README.rdoc.erb +38 -0
  20. data/data/ore/templates/base/README.tt.erb +44 -0
  21. data/data/ore/templates/base/Rakefile.erb +23 -0
  22. data/data/ore/templates/base/gemspec.yml.erb +23 -0
  23. data/data/ore/templates/base/lib/:namespace_dir:.rb.erb +1 -0
  24. data/data/ore/templates/base/lib/:namespace_dir:/version.rb.erb +8 -0
  25. data/data/ore/templates/bundler/Gemfile.erb +20 -0
  26. data/data/ore/templates/bundler/_dependencies.erb +1 -0
  27. data/data/ore/templates/jeweler_tasks/_dependencies.erb +3 -0
  28. data/data/ore/templates/jeweler_tasks/_tasks.erb +17 -0
  29. data/data/ore/templates/ore_tasks/_dependencies.erb +1 -0
  30. data/data/ore/templates/ore_tasks/_tasks.erb +12 -0
  31. data/data/ore/templates/rdoc/_tasks.erb +6 -0
  32. data/data/ore/templates/rspec/.rspec +1 -0
  33. data/data/ore/templates/rspec/_dependencies.erb +3 -0
  34. data/data/ore/templates/rspec/_tasks.erb +14 -0
  35. data/data/ore/templates/rspec/spec/:namespace_dir:_spec.rb.erb +8 -0
  36. data/data/ore/templates/rspec/spec/spec_helper.rb.erb +7 -0
  37. data/data/ore/templates/test_unit/test/helper.rb.erb +24 -0
  38. data/data/ore/templates/test_unit/test/test_:name:.rb.erb +5 -0
  39. data/data/ore/templates/yard/.yardopts.erb +1 -0
  40. data/data/ore/templates/yard/_dependencies.erb +1 -0
  41. data/data/ore/templates/yard/_gem.erb +1 -0
  42. data/data/ore/templates/yard/_tasks.erb +13 -0
  43. data/gemspec.yml +21 -0
  44. data/lib/ore.rb +3 -0
  45. data/lib/ore/checks.rb +85 -0
  46. data/lib/ore/cli.rb +120 -0
  47. data/lib/ore/config.rb +52 -0
  48. data/lib/ore/defaults.rb +137 -0
  49. data/lib/ore/dependency.rb +62 -0
  50. data/lib/ore/document_file.rb +118 -0
  51. data/lib/ore/exceptions.rb +3 -0
  52. data/lib/ore/exceptions/exception.rb +4 -0
  53. data/lib/ore/exceptions/invalid_metadata.rb +6 -0
  54. data/lib/ore/exceptions/project_not_found.rb +6 -0
  55. data/lib/ore/generator.rb +247 -0
  56. data/lib/ore/naming.rb +95 -0
  57. data/lib/ore/paths.rb +143 -0
  58. data/lib/ore/project.rb +568 -0
  59. data/lib/ore/settings.rb +236 -0
  60. data/lib/ore/specification.rb +29 -0
  61. data/lib/ore/template.rb +3 -0
  62. data/lib/ore/template/directory.rb +179 -0
  63. data/lib/ore/template/helpers.rb +144 -0
  64. data/lib/ore/template/interpolations.rb +31 -0
  65. data/lib/ore/versions.rb +3 -0
  66. data/lib/ore/versions/exceptions.rb +1 -0
  67. data/lib/ore/versions/exceptions/invalid_version.rb +8 -0
  68. data/lib/ore/versions/version.rb +75 -0
  69. data/lib/ore/versions/version_constant.rb +126 -0
  70. data/lib/ore/versions/version_file.rb +66 -0
  71. data/lib/rubygems_plugin.rb +40 -0
  72. data/ore.gemspec +6 -0
  73. data/spec/dependency_spec.rb +36 -0
  74. data/spec/document_file_spec.rb +29 -0
  75. data/spec/helpers/files.rb +7 -0
  76. data/spec/helpers/files/.document +5 -0
  77. data/spec/helpers/files/VERSION +1 -0
  78. data/spec/helpers/files/VERSION.yml +5 -0
  79. data/spec/helpers/projects.rb +13 -0
  80. data/spec/helpers/projects/dm-plugin/Gemfile +3 -0
  81. data/spec/helpers/projects/dm-plugin/VERSION +1 -0
  82. data/spec/helpers/projects/dm-plugin/dm-plugin.gemspec +10 -0
  83. data/spec/helpers/projects/dm-plugin/gemspec.yml +7 -0
  84. data/spec/helpers/projects/dm-plugin/lib/dm-plugin.rb +1 -0
  85. data/spec/helpers/projects/explicit/gemspec.yml +10 -0
  86. data/spec/helpers/projects/explicit/lib/explicit/version.rb +15 -0
  87. data/spec/helpers/projects/ffi-binding/gemspec.yml +7 -0
  88. data/spec/helpers/projects/ffi-binding/lib/ffi/binding/version.rb +5 -0
  89. data/spec/helpers/projects/jewelery/VERSION +1 -0
  90. data/spec/helpers/projects/jewelery/bin/jewelery +3 -0
  91. data/spec/helpers/projects/jewelery/gemspec.yml +4 -0
  92. data/spec/helpers/projects/jewelery/jewelery.gemspec +10 -0
  93. data/spec/helpers/projects/jewelery/lib/jewelery.rb +4 -0
  94. data/spec/helpers/projects/jewelery/lib/jewelery/rubies.rb +4 -0
  95. data/spec/helpers/projects/minimal/gemspec.yml +4 -0
  96. data/spec/helpers/projects/minimal/lib/minimal.rb +2 -0
  97. data/spec/naming_spec.rb +48 -0
  98. data/spec/projects/dm_plugin_project_spec.rb +29 -0
  99. data/spec/projects/explicit_project_spec.rb +33 -0
  100. data/spec/projects/ffi_binding_project_spec.rb +21 -0
  101. data/spec/projects/jeweler_project_spec.rb +17 -0
  102. data/spec/projects/minimal_project_spec.rb +17 -0
  103. data/spec/projects/project_examples.rb +34 -0
  104. data/spec/spec_helper.rb +4 -0
  105. data/spec/versions/version_file_spec.rb +28 -0
  106. data/spec/versions/version_spec.rb +53 -0
  107. metadata +226 -0
@@ -0,0 +1,236 @@
1
+ require 'ore/exceptions/invalid_metadata'
2
+ require 'ore/versions/version'
3
+ require 'ore/dependency'
4
+
5
+ module Ore
6
+ module Settings
7
+ protected
8
+
9
+ #
10
+ # Sets the version of the project.
11
+ #
12
+ # @param [Hash<Integer>, String] version
13
+ # The version from the metadata file.
14
+ #
15
+ # @raise [InvalidVersion]
16
+ # The version must either be a `String` or a `Hash`.
17
+ #
18
+ def set_version!(version)
19
+ case version
20
+ when Hash
21
+ major = version['major']
22
+ minor = version['minor']
23
+ patch = version['patch']
24
+ build = version['build']
25
+
26
+ @version = Versions::Version.new(major,minor,patch,build)
27
+ when String
28
+ @version = Versions::Version.parse(version)
29
+ else
30
+ raise(InvalidMetadata,"version must be a Hash or a String")
31
+ end
32
+ end
33
+
34
+ #
35
+ # Sets the license(s) of the project.
36
+ #
37
+ # @param [Array, String] license
38
+ # The license(s) of the project.
39
+ #
40
+ def set_license!(license)
41
+ if license.kind_of?(Array)
42
+ license.each { |name| @licenses << name.to_s }
43
+ else
44
+ @licenses << license.to_s
45
+ end
46
+ end
47
+
48
+ #
49
+ # Sets the authors of the project.
50
+ #
51
+ # @param [Array<String>, String] authors
52
+ # The authors listed in the metadata file.
53
+ #
54
+ def set_authors!(authors)
55
+ if authors.kind_of?(Array)
56
+ @authors += authors
57
+ else
58
+ @authors << authors
59
+ end
60
+ end
61
+
62
+ #
63
+ # Sets the release date of the project.
64
+ #
65
+ # @param [String] date
66
+ # The release date from the metadata file.
67
+ #
68
+ def set_date!(date)
69
+ @date = Date.parse(date)
70
+ end
71
+
72
+ #
73
+ # Sets the require-paths of the project.
74
+ #
75
+ # @param [Array<String>, String] paths
76
+ # The require-paths or the glob-pattern listed in the metadata file.
77
+ #
78
+ def set_require_paths!(paths)
79
+ if paths.kind_of?(Array)
80
+ paths.each { |path| add_require_path(path) }
81
+ else
82
+ glob(paths) { |path| add_require_path(path) }
83
+ end
84
+ end
85
+
86
+ #
87
+ # Sets the executables of the project.
88
+ #
89
+ # @param [Array<String>, String]
90
+ # The executable names or the glob-pattern listed in the metadata
91
+ # file.
92
+ #
93
+ def set_executables!(paths)
94
+ if paths.kind_of?(Array)
95
+ paths.each { |path| add_executable(path) }
96
+ else
97
+ glob(paths) { |path| add_executable(path) }
98
+ end
99
+ end
100
+
101
+ #
102
+ # Sets the default executable of the project.
103
+ #
104
+ # @param [String] name
105
+ # The default executable name listed in the metadata file.
106
+ #
107
+ def set_default_executable!(name)
108
+ if @executables.include?(name)
109
+ @default_executable = name
110
+ else
111
+ warn "#{name} is not in the executables list"
112
+ end
113
+ end
114
+
115
+ #
116
+ # Sets the extra documentation files of the project.
117
+ #
118
+ # @param [Array<String>, String] paths
119
+ # The file paths or the glob-pattern listed in the metadata file.
120
+ #
121
+ def set_extra_doc_files!(paths)
122
+ if paths.kind_of?(Array)
123
+ paths.each { |path| add_extra_doc_file(path) }
124
+ else
125
+ glob(paths) { |path| add_extra_doc_file(path) }
126
+ end
127
+ end
128
+
129
+ #
130
+ # Sets the files of the project.
131
+ #
132
+ # @param [Array<String>, String] paths
133
+ # The files or the glob-pattern listed in the metadata file.
134
+ #
135
+ def set_files!(paths)
136
+ if paths.kind_of?(Array)
137
+ paths.each { |path| add_file(path) }
138
+ else
139
+ glob(paths) { |path| add_file(path) }
140
+ end
141
+ end
142
+
143
+ #
144
+ # Sets the test-files of the project.
145
+ #
146
+ # @param [Array<String>, String] paths
147
+ # The test-files of the glob-pattern listed in the metadata file.
148
+ #
149
+ def set_test_files!(paths)
150
+ if paths.kind_of?(Array)
151
+ paths.each { |path| add_test_file(path) }
152
+ else
153
+ glob(paths) { |path| add_test_file(path) }
154
+ end
155
+ end
156
+
157
+ #
158
+ # Sets the Ruby version required by the project.
159
+ #
160
+ # @param [String] version
161
+ # The version requirement.
162
+ #
163
+ def set_required_ruby_version!(version)
164
+ @required_ruby_version = version.to_s
165
+ end
166
+
167
+ #
168
+ # Sets the RubyGems version required by the project.
169
+ #
170
+ # @param [String] version
171
+ # The version requirement.
172
+ #
173
+ def set_required_rubygems_version!(version)
174
+ @required_rubygems_version = version.to_s
175
+ end
176
+
177
+ #
178
+ # Sets the dependencies of the project.
179
+ #
180
+ # @param [Hash{String => String}] dependencies
181
+ # The dependencey names and versions listed in the metadata file.
182
+ #
183
+ # @raise [InvalidMetadata]
184
+ # The dependencies must be a `Hash`.
185
+ #
186
+ def set_dependencies!(dependencies)
187
+ unless dependencies.kind_of?(Hash)
188
+ raise(InvalidMetadata,"dependencies must be a Hash")
189
+ end
190
+
191
+ dependencies.each do |name,versions|
192
+ @dependencies << Dependency.parse_versions(name,versions)
193
+ end
194
+ end
195
+
196
+ #
197
+ # Sets the runtime-dependencies of the project.
198
+ #
199
+ # @param [Hash{String => String}] dependencies
200
+ # The runtime-dependencey names and versions listed in the metadata
201
+ # file.
202
+ #
203
+ # @raise [InvalidMetadata]
204
+ # The runtime-dependencies must be a `Hash`.
205
+ #
206
+ def set_runtime_dependencies!(dependencies)
207
+ unless dependencies.kind_of?(Hash)
208
+ raise(InvalidMetadata,"runtime_dependencies must be a Hash")
209
+ end
210
+
211
+ dependencies.each do |name,versions|
212
+ @runtime_dependencies << Dependency.parse_versions(name,versions)
213
+ end
214
+ end
215
+
216
+ #
217
+ # Sets the development-dependencies of the project.
218
+ #
219
+ # @param [Hash{String => String}] dependencies
220
+ # The development-dependencey names and versions listed in the
221
+ # metadata file.
222
+ #
223
+ # @raise [InvalidMetadata]
224
+ # The development-dependencies must be a `Hash`.
225
+ #
226
+ def set_development_dependencies!(dependencies)
227
+ unless dependencies.kind_of?(Hash)
228
+ raise(InvalidMetadata,"development_dependencies must be a Hash")
229
+ end
230
+
231
+ dependencies.each do |name,versions|
232
+ @development_dependencies << Dependency.parse_versions(name,versions)
233
+ end
234
+ end
235
+ end
236
+ end
@@ -0,0 +1,29 @@
1
+ require 'ore/project'
2
+
3
+ module Ore
4
+ #
5
+ # Acts as a drop-in replacement for calling `Gem::Specification.new`
6
+ # in a projects gemspec file.
7
+ #
8
+ module Specification
9
+ #
10
+ # Creates a new Gem Specification, and automatically populates it
11
+ # using the metadata file.
12
+ #
13
+ # @yield [gemspec]
14
+ # The given block will be passed the populated Gem Specification
15
+ # object.
16
+ #
17
+ # @yieldparam [Gem::Specification] gemspec
18
+ # The newly created Gem Specification.
19
+ #
20
+ # @return [Gem::Specification]
21
+ # The Gem Specification.
22
+ #
23
+ # @see Project#to_gemspec
24
+ #
25
+ def Specification.new(&block)
26
+ Project.find.to_gemspec(&block)
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,3 @@
1
+ require 'ore/template/directory'
2
+ require 'ore/template/interpolations'
3
+ require 'ore/template/helpers'
@@ -0,0 +1,179 @@
1
+ require 'find'
2
+
3
+ module Ore
4
+ module Template
5
+ class Directory
6
+
7
+ # Files or directory names to ignore
8
+ @@ignore = %w[.git]
9
+
10
+ # The known markup languages and file extensions
11
+ @@markups = {
12
+ :markdown => %w[.md .markdown],
13
+ :textile => %w[.tt .textile],
14
+ :rdoc => %w[.rdoc]
15
+ }
16
+
17
+ # The path of the template directory
18
+ attr_reader :path
19
+
20
+ # The directories within the template directory
21
+ attr_reader :directories
22
+
23
+ # The static files in the template directory
24
+ attr_reader :files
25
+
26
+ # The ERb templates in the template directory
27
+ attr_reader :templates
28
+
29
+ # The include templates in the template directory
30
+ attr_reader :includes
31
+
32
+ #
33
+ # Initializes a new template directory.
34
+ #
35
+ # @param [String] path
36
+ # The path to the template directory.
37
+ #
38
+ def initialize(path)
39
+ @path = File.expand_path(path)
40
+
41
+ @directories = []
42
+ @files = {}
43
+ @templates = {}
44
+ @includes = Hash.new { |hash,key| hash[key] = {} }
45
+
46
+ scan!
47
+ end
48
+
49
+ #
50
+ # Enumerates through the directories in the template directory.
51
+ #
52
+ # @yield [path]
53
+ # The given block will be passed each directory path.
54
+ #
55
+ # @yieldparam [String] path
56
+ # The relative path of a directory within the template directory.
57
+ #
58
+ def each_directory(&block)
59
+ @directories.each(&block)
60
+ end
61
+
62
+ #
63
+ # Enumerates through every file in the template directory.
64
+ #
65
+ # @param [Symbol] markup
66
+ # The markup to look for.
67
+ #
68
+ # @yield [path]
69
+ # The given block will be passed each file path.
70
+ #
71
+ # @yieldparam [String] path
72
+ # A relative path of a file within the template directory.
73
+ #
74
+ def each_file(markup)
75
+ @files.each do |dest,file|
76
+ if (formatted_like?(dest,markup) || !formatted?(dest))
77
+ yield dest, file
78
+ end
79
+ end
80
+ end
81
+
82
+ #
83
+ # Enumerates over every template within the template directory.
84
+ #
85
+ # @param [Symbol] markup
86
+ # The markup to look for.
87
+ #
88
+ # @yield [path]
89
+ # The given block will be passed each template path.
90
+ #
91
+ # @yieldparam [String] path
92
+ # A relative path of a template within the template directory.
93
+ #
94
+ def each_template(markup)
95
+ @templates.each do |dest,file|
96
+ if (formatted_like?(dest,markup) || !formatted?(dest))
97
+ yield dest, file
98
+ end
99
+ end
100
+ end
101
+
102
+ protected
103
+
104
+ #
105
+ # Scans the template directory recursively recording the directories,
106
+ # files and partial templates.
107
+ #
108
+ def scan!
109
+ Dir.chdir(@path) do
110
+ Find.find('.') do |file|
111
+ next if file == '.'
112
+
113
+ # ignore the ./
114
+ file = file[2..-1]
115
+ name = File.basename(file)
116
+
117
+ # ignore certain files/directories
118
+ Find.prune if @@ignore.include?(name)
119
+
120
+ if File.directory?(file)
121
+ @directories << file
122
+ elsif File.file?(file)
123
+ src = File.join(@path,file)
124
+
125
+ case File.extname(name)
126
+ when '.erb'
127
+ # erb template
128
+ if name[0,1] == '_'
129
+ # partial template
130
+ template_dir = File.dirname(file)
131
+ template_name = name[1...-4].to_sym
132
+
133
+ @includes[template_dir][template_name] = src
134
+ else
135
+ dest = file[0...-4]
136
+
137
+ @templates[dest] = src
138
+ end
139
+ else
140
+ # static file
141
+ @files[file] = src
142
+ end
143
+ end
144
+ end
145
+ end
146
+ end
147
+
148
+ #
149
+ # Determines whether a file is markup formatted.
150
+ #
151
+ # @param [String] path
152
+ # The path to the file.
153
+ #
154
+ # @return [Boolean]
155
+ # Specifies whether the file is formatting.
156
+ #
157
+ def formatted?(path)
158
+ @@markups.values.any? { |exts| exts.include?(File.extname(path)) }
159
+ end
160
+
161
+ #
162
+ # Determines if a file has a specific type of markup formatting.
163
+ #
164
+ # @param [String] path
165
+ # The path to the file.
166
+ #
167
+ # @param [Symbol] markup
168
+ # The specified type of markup.
169
+ #
170
+ # @return [Boolean]
171
+ # Specifies whether the file has the sepcified formatting.
172
+ #
173
+ def formatted_like?(path,markup)
174
+ @@markups[markup].include?(File.extname(path))
175
+ end
176
+
177
+ end
178
+ end
179
+ end