├── var ├── name ├── title ├── version ├── created ├── organization ├── summary ├── authors ├── copyrights ├── repositories ├── requirements ├── description └── resources ├── pkg ├── .gitignore └── pic.gemspec ├── .ruby ├── Gemfile ├── .gitignore ├── .travis.yml ├── MANIFEST.txt ├── HISTORY.md ├── Assembly ├── demo └── pic.md ├── LICENSE.txt ├── .index ├── README.md └── lib └── pic.rb /var/name: -------------------------------------------------------------------------------- 1 | pic 2 | -------------------------------------------------------------------------------- /var/title: -------------------------------------------------------------------------------- 1 | PIC 2 | -------------------------------------------------------------------------------- /var/version: -------------------------------------------------------------------------------- 1 | 0.1.0 2 | -------------------------------------------------------------------------------- /var/created: -------------------------------------------------------------------------------- 1 | 2011-07-13 2 | -------------------------------------------------------------------------------- /pkg/.gitignore: -------------------------------------------------------------------------------- 1 | *.gem 2 | *.gz 3 | -------------------------------------------------------------------------------- /var/organization: -------------------------------------------------------------------------------- 1 | rubyworks 2 | -------------------------------------------------------------------------------- /var/summary: -------------------------------------------------------------------------------- 1 | Edited Pictures for Ruby 2 | -------------------------------------------------------------------------------- /var/authors: -------------------------------------------------------------------------------- 1 | --- 2 | - Thomas Sawyer 3 | -------------------------------------------------------------------------------- /var/copyrights: -------------------------------------------------------------------------------- 1 | --- 2 | - 2011 Rubyworks (BSD-2-Clause) 3 | 4 | -------------------------------------------------------------------------------- /.ruby: -------------------------------------------------------------------------------- 1 | ruby 1.9.3p327 (2012-11-10 revision 37606) [x86_64-linux] 2 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source "http://rubygems.org" 2 | gemspec :path=>'pkg' 3 | -------------------------------------------------------------------------------- /var/repositories: -------------------------------------------------------------------------------- 1 | --- 2 | upstream: git://github.com/proutils/pic.git 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .fire/digest 2 | .yardoc 3 | doc 4 | log 5 | tmp 6 | web 7 | work/sandbox 8 | DEMO*.* 9 | -------------------------------------------------------------------------------- /var/requirements: -------------------------------------------------------------------------------- 1 | --- 2 | - qed (test) 3 | - ae (test) 4 | - detroit (build) 5 | - reap (build) 6 | 7 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | --- 2 | script: "bundle exec qed" 3 | rvm: 4 | - 1.8.7 5 | - 1.9.2 6 | - 1.9.3 7 | - rbx 8 | - rbx-19mode 9 | - jruby 10 | - jruby-19mode 11 | - ree 12 | -------------------------------------------------------------------------------- /MANIFEST.txt: -------------------------------------------------------------------------------- 1 | #!mast -x *.lock .index .ruby .yardopts bin demo lib man spec test try [A-Z]*.* 2 | .index 3 | .ruby 4 | demo/pic.md 5 | lib/pic.rb 6 | LICENSE.txt 7 | HISTORY.md 8 | README.md 9 | DEMO.md 10 | -------------------------------------------------------------------------------- /var/description: -------------------------------------------------------------------------------- 1 | PIC is a pattern matching library, like regular expressions, based on Cobol 2 | edited pictures. It's advantage over regular expressions is it more concise 3 | syntax which geared specifically toward validation of user input. 4 | -------------------------------------------------------------------------------- /var/resources: -------------------------------------------------------------------------------- 1 | --- 2 | home: http://rubyworks.github.com/pic 3 | code: http://github.com/rubyworks/pic 4 | bugs: http://github.com/rubyworks/pic/issues 5 | mail: http://groups.google.com/groups/rubyworks-mailinglist 6 | chat: irc://chat.us.freenode.net/rubyworks 7 | 8 | -------------------------------------------------------------------------------- /HISTORY.md: -------------------------------------------------------------------------------- 1 | # RELEASE HISTORY 2 | 3 | ## 0.1.0 / 2012-03-20 4 | 5 | This is the initial public release of PIC. PIC is still under development 6 | and should be considered betaware, but it's API is stable and usable 7 | enough to warrant a release. 8 | 9 | Changes: 10 | 11 | * Happy First Release Day! 12 | 13 | -------------------------------------------------------------------------------- /Assembly: -------------------------------------------------------------------------------- 1 | --- 2 | gem: 3 | gemspec: pkg/pic.gemspec 4 | active: true 5 | 6 | github: 7 | gh_pages: web 8 | 9 | dnote: 10 | title: Source Notes 11 | labels: ~ 12 | output: log/notes.html 13 | 14 | yard: 15 | active: false 16 | yardopts: true 17 | priority: 2 18 | 19 | qed: 20 | files: demo 21 | 22 | qedoc: 23 | title: Edited Pictures for Ruby 24 | files: demo 25 | output: DEMO.md 26 | 27 | vclog: 28 | output: 29 | - log/history.html 30 | - log/changes.html 31 | 32 | email: 33 | file: ~ 34 | subject: ~ 35 | mailto: 36 | - ruby-talk@ruby-lang.org 37 | - rubyworks-mailinglist@googlegroups.com 38 | #parts: [readme] 39 | 40 | -------------------------------------------------------------------------------- /demo/pic.md: -------------------------------------------------------------------------------- 1 | # Ruby Data Pictures 2 | 3 | ## Overview 4 | 5 | PIC is pattern matching system roughly based on Cobol Pictures. It serves 6 | as an alternative to Regular Expressions for common data format needs. 7 | 8 | ## Requiring the Library 9 | 10 | To use the library, first require "pic". 11 | 12 | require 'pic' 13 | 14 | ## Basic Regexp Conversions 15 | 16 | PIC['X'].to_re #=> /./ 17 | PIC['A'].to_re #=> /[A-Za-z]/ 18 | PIC['W'].to_re #=> /\w/ 19 | PIC['9'].to_re #=> /\d/ 20 | PIC['Z'].to_re #=> /\d*/ 21 | 22 | PIC['.'].to_re #=> /\./ 23 | PIC[','].to_re #=> /\,/ 24 | PIC['-'].to_re #=> /\-/ 25 | PIC['/'].to_re #=> /\// 26 | 27 | ## General Regexp Conversions 28 | 29 | PIC['XX'].to_re #=> /../ 30 | PIC['AA'].to_re #=> /[A-Za-z][A-Za-z]/ 31 | PIC['WW'].to_re #=> /\w\w/ 32 | 33 | ## Advanced Regexp Conversions 34 | 35 | PIC['99.99'].to_re #=> /\d\d\.\d\d/ 36 | 37 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | BSD-2-Clause License 2 | 3 | Redistribution and use in source and binary forms, with or without modification, are 4 | permitted provided that the following conditions are met: 5 | 6 | 1. Redistributions of source code must retain the above copyright notice, this list of 7 | conditions and the following disclaimer. 8 | 9 | 2. Redistributions in binary form must reproduce the above copyright notice, this list 10 | of conditions and the following disclaimer in the documentation and/or other materials 11 | provided with the distribution. 12 | 13 | THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 14 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 15 | PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR 16 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 17 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 18 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 19 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 20 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 21 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 22 | 23 | -------------------------------------------------------------------------------- /.index: -------------------------------------------------------------------------------- 1 | --- 2 | type: ruby 3 | revision: 2013 4 | sources: 5 | - var 6 | authors: 7 | - name: Thomas Sawyer 8 | email: transfire@gmail.com 9 | organizations: [] 10 | requirements: 11 | - groups: 12 | - test 13 | development: true 14 | name: qed 15 | - groups: 16 | - test 17 | development: true 18 | name: ae 19 | - groups: 20 | - build 21 | development: true 22 | name: detroit 23 | - groups: 24 | - build 25 | development: true 26 | name: reap 27 | conflicts: [] 28 | alternatives: [] 29 | resources: 30 | - type: home 31 | uri: http://rubyworks.github.com/pic 32 | label: Homepage 33 | - type: code 34 | uri: http://github.com/rubyworks/pic 35 | label: Source Code 36 | - type: bugs 37 | uri: http://github.com/rubyworks/pic/issues 38 | label: Issue Tracker 39 | - type: mail 40 | uri: http://groups.google.com/groups/rubyworks-mailinglist 41 | label: Mailing List 42 | - type: chat 43 | uri: irc://chat.us.freenode.net/rubyworks 44 | label: IRC Channel 45 | repositories: 46 | - name: upstream 47 | scm: git 48 | uri: git://github.com/proutils/pic.git 49 | categories: [] 50 | paths: 51 | load: 52 | - lib 53 | copyrights: 54 | - holder: Rubyworks 55 | year: '2011' 56 | license: BSD-2-Clause 57 | created: '2011-07-13' 58 | summary: Edited Pictures for Ruby 59 | title: PIC 60 | version: 0.1.0 61 | name: pic 62 | description: ! 'PIC is a pattern matching library, like regular expressions, based 63 | on Cobol 64 | 65 | edited pictures. It''s advantage over regular expressions is it more concise 66 | 67 | syntax which geared specifically toward validation of user input.' 68 | date: '2012-12-18' 69 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [Website](http://rubyworks.github.com/pic) / 2 | [Report Issue](http://github.com/rubyworks/pic/issues) / 3 | [Source Code](http://github.com/rubyworks/pic) 4 | ( [![Build Status](https://secure.travis-ci.org/rubyworks/pic.png)](http://travis-ci.org/rubyworks/pic) ) 5 | 6 | 7 | # PIC 8 | 9 | PIC is pattern matching system roughly based on Cobol Pictures. It serves 10 | as an alternative to Regular Expressions for common data format needs. 11 | 12 | 13 | ## Usage 14 | 15 | Here is a simply example. 16 | 17 | ~~~ruby 18 | PIC['Z.99'].to_re #=> /\d*\.\d\d/ 19 | ~~~ 20 | 21 | 22 | ## Status 23 | 24 | Currently PIC is very much in a state of "design development". It will take 25 | some time to workout the best correlations between picture and regular 26 | expression. Suggestions and patches welcome! 27 | 28 | 29 | ## Installation 30 | 31 | Per the usual RubyGems way: 32 | 33 | $ gem install pic 34 | 35 | 36 | ## Reference Material 37 | 38 | The following links help explain concept of Edited Pictures. 39 | 40 | * [Edited Pictures](http://www.csis.ul.ie/cobol/course/EditedPics.htm) 41 | 42 | 43 | ## Contributing 44 | 45 | ### General Discussion 46 | 47 | If you do not have specific issue to report but would still like to discuss this library, 48 | you can send a message to the [Rubyworks Mailing List](http://groups.google.com/rubyworks-mailinglist), 49 | or try to catch up with us via the [#rubyworks](irc://irc.freenode.net/rubyworks) IRC channel. 50 | 51 | ### Submitting Patches 52 | 53 | Sending a code snippet is fine for very small changes. But beyond a few lines 54 | of code, please use git via Github to submit pull requests. It is best to submit 55 | a dedicated feature branch, and tests are *always* much appreciated. 56 | 57 | 58 | ## Copyright & License 59 | 60 | PIC is copyrighted free software. 61 | 62 | Copyright (c) 2011 Rubyworks (BSD-2-Clause Licensed) 63 | 64 | PIC is freely redistributable and modifiable in accordance with the 65 | [BSD-2-Clause](http://spdx.org/licenses/bsd-2-clause) license. 66 | 67 | See LICENSE.txt for details. 68 | -------------------------------------------------------------------------------- /lib/pic.rb: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2011 Rubyworks 2 | # 3 | # Redistribution and use in source and binary forms, with or without modification, are 4 | # permitted provided that the following conditions are met: 5 | # 6 | # 1. Redistributions of source code must retain the above copyright notice, this list of 7 | # conditions and the following disclaimer. 8 | # 9 | # 2. Redistributions in binary form must reproduce the above copyright notice, this list 10 | # of conditions and the following disclaimer in the documentation and/or other materials 11 | # provided with the distribution. 12 | # 13 | # THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 14 | # BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 15 | # PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR 16 | # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 17 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 18 | # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 19 | # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 20 | # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 21 | # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 22 | 23 | # PIC namespace. 24 | # 25 | module PIC 26 | 27 | # 28 | # Shortcut to `PIC::Template.new(pic)`. 29 | # 30 | # @return [PIC::Template] 31 | # 32 | def self.[](pic) 33 | Template.new(pic) 34 | end 35 | 36 | # Template class encapsulates a picture, handles 37 | # converting it to a regular expression and delagates 38 | # to it for matching. 39 | # 40 | class Template 41 | 42 | # 43 | # New pic template. 44 | # 45 | # @param [String] pic 46 | # Picture to use for matching. 47 | # 48 | def initialize(pic) 49 | @pic = pic 50 | end 51 | 52 | # 53 | # The picture. 54 | # 55 | # @return [String] picture. 56 | # 57 | attr :pic 58 | 59 | # 60 | # Convert picture to a regular epression. 61 | # 62 | def to_re 63 | re = '' 64 | pic.scan(SCAN) do |s,c| 65 | re << remap(s) + recnt(c) 66 | end 67 | Regexp.new(re) 68 | end 69 | 70 | # 71 | # Alias for `#to_re`. 72 | # 73 | alias_method :to_regexp, :to_re 74 | 75 | # 76 | # Match picture to given string. 77 | # 78 | # @param [String] string 79 | # String to match picture against. 80 | # 81 | # @return [Fixnum] index position in string of match. 82 | # 83 | def =~(string) 84 | to_re =~ string.to_str 85 | end 86 | 87 | alias === =~ 88 | 89 | # 90 | # Checks for a non-match of the picture to a given string. 91 | # 92 | # @param [String] string 93 | # String to match picture against. 94 | # 95 | # @return [Fixnum] index position in string of match. 96 | # 97 | def !~(string) 98 | to_re !~ string.to_str 99 | end 100 | 101 | private 102 | 103 | # 104 | def remap(s) 105 | REMAP[s] || raise(ArgumentError) #('\' + s) 106 | end 107 | 108 | # 109 | def recnt(c) 110 | return '' unless c 111 | 112 | case c 113 | when /\[(\d+)\.\.(\d+)\]/ 114 | '{'+$1+','+$2+'}' 115 | when /\[(\d+)\,(\d+)\]/ 116 | '{'+$1+','+$2+'}' 117 | when /\[(\d+)\]/ 118 | '{'+$1+'}' 119 | end 120 | end 121 | 122 | # 123 | SCAN = /(\S)(\[.*?\])?/ 124 | 125 | # 126 | REMAP = { 127 | 'X' => '.', 128 | '9' => '\d', 129 | 'Z' => '\d*', 130 | '0' => '\d', 131 | 'A' => '[A-Za-z]', 132 | 'W' => '\w', 133 | '.' => '\.', 134 | ',' => '\,', 135 | '-' => '\-', 136 | '/' => '\/' 137 | } 138 | 139 | end 140 | 141 | end 142 | -------------------------------------------------------------------------------- /pkg/pic.gemspec: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | 3 | require 'yaml' 4 | require 'pathname' 5 | 6 | module Indexer 7 | 8 | # Convert index data into a gemspec. 9 | # 10 | # Notes: 11 | # * Assumes all executables are in bin/. 12 | # * Does not yet handle default_executable setting. 13 | # * Does not yet handle platform setting. 14 | # * Does not yet handle required_ruby_version. 15 | # * Support for rdoc entries is weak. 16 | # 17 | class GemspecExporter 18 | 19 | # File globs to include in package --unless a manifest file exists. 20 | FILES = ".index .yardopts alt bin data demo ext features lib man spec test try* [A-Z]*.*" unless defined?(FILES) 21 | 22 | # File globs to omit from FILES. 23 | OMIT = "Config.rb" unless defined?(OMIT) 24 | 25 | # Standard file patterns. 26 | PATTERNS = { 27 | :root => '{.index,Gemfile}', 28 | :bin => 'bin/*', 29 | :lib => 'lib/{**/}*', #.rb', 30 | :ext => 'ext/{**/}extconf.rb', 31 | :doc => '*.{txt,rdoc,md,markdown,tt,textile}', 32 | :test => '{test,spec}/{**/}*.rb' 33 | } unless defined?(PATTERNS) 34 | 35 | # For which revision of indexer spec is this converter intended? 36 | REVISION = 2013 unless defined?(REVISION) 37 | 38 | # 39 | def self.gemspec 40 | new.to_gemspec 41 | end 42 | 43 | # 44 | attr :metadata 45 | 46 | # 47 | def initialize(metadata=nil) 48 | @root_check = false 49 | 50 | if metadata 51 | root_dir = metadata.delete(:root) 52 | if root_dir 53 | @root = root_dir 54 | @root_check = true 55 | end 56 | metadata = nil if metadata.empty? 57 | end 58 | 59 | @metadata = metadata || YAML.load_file(root + '.index') 60 | 61 | if @metadata['revision'].to_i != REVISION 62 | warn "This gemspec exporter was not designed for this revision of index metadata." 63 | end 64 | end 65 | 66 | # 67 | def has_root? 68 | root ? true : false 69 | end 70 | 71 | # 72 | def root 73 | return @root if @root || @root_check 74 | @root_check = true 75 | @root = find_root 76 | end 77 | 78 | # 79 | def manifest 80 | return nil unless root 81 | @manifest ||= Dir.glob(root + 'manifest{,.txt}', File::FNM_CASEFOLD).first 82 | end 83 | 84 | # 85 | def scm 86 | return nil unless root 87 | @scm ||= %w{git hg}.find{ |m| (root + ".#{m}").directory? }.to_sym 88 | end 89 | 90 | # 91 | def files 92 | return [] unless root 93 | @files ||= \ 94 | if manifest 95 | File.readlines(manifest). 96 | map{ |line| line.strip }. 97 | reject{ |line| line.empty? || line[0,1] == '#' } 98 | else 99 | list = [] 100 | Dir.chdir(root) do 101 | FILES.split(/\s+/).each do |pattern| 102 | list.concat(glob(pattern)) 103 | end 104 | OMIT.split(/\s+/).each do |pattern| 105 | list = list - glob(pattern) 106 | end 107 | end 108 | list 109 | end.select{ |path| File.file?(path) }.uniq 110 | end 111 | 112 | # 113 | def glob_files(pattern) 114 | return [] unless root 115 | Dir.chdir(root) do 116 | Dir.glob(pattern).select do |path| 117 | File.file?(path) && files.include?(path) 118 | end 119 | end 120 | end 121 | 122 | def patterns 123 | PATTERNS 124 | end 125 | 126 | def executables 127 | @executables ||= \ 128 | glob_files(patterns[:bin]).map do |path| 129 | File.basename(path) 130 | end 131 | end 132 | 133 | def extensions 134 | @extensions ||= \ 135 | glob_files(patterns[:ext]).map do |path| 136 | File.basename(path) 137 | end 138 | end 139 | 140 | def name 141 | metadata['name'] || metadata['title'].downcase.gsub(/\W+/,'_') 142 | end 143 | 144 | def homepage 145 | page = ( 146 | metadata['resources'].find{ |r| r['type'] =~ /^home/i } || 147 | metadata['resources'].find{ |r| r['name'] =~ /^home/i } || 148 | metadata['resources'].find{ |r| r['name'] =~ /^web/i } 149 | ) 150 | page ? page['uri'] : false 151 | end 152 | 153 | def licenses 154 | metadata['copyrights'].map{ |c| c['license'] }.compact 155 | end 156 | 157 | def require_paths 158 | paths = metadata['paths'] || {} 159 | paths['load'] || ['lib'] 160 | end 161 | 162 | # 163 | # Convert to gemnspec. 164 | # 165 | def to_gemspec 166 | if has_root? 167 | Gem::Specification.new do |gemspec| 168 | to_gemspec_data(gemspec) 169 | to_gemspec_paths(gemspec) 170 | end 171 | else 172 | Gem::Specification.new do |gemspec| 173 | to_gemspec_data(gemspec) 174 | to_gemspec_paths(gemspec) 175 | end 176 | end 177 | end 178 | 179 | # 180 | # Convert pure data settings. 181 | # 182 | def to_gemspec_data(gemspec) 183 | gemspec.name = name 184 | gemspec.version = metadata['version'] 185 | gemspec.summary = metadata['summary'] 186 | gemspec.description = metadata['description'] 187 | 188 | metadata['authors'].each do |author| 189 | gemspec.authors << author['name'] 190 | 191 | if author.has_key?('email') 192 | if gemspec.email 193 | gemspec.email << author['email'] 194 | else 195 | gemspec.email = [author['email']] 196 | end 197 | end 198 | end 199 | 200 | gemspec.licenses = licenses 201 | 202 | requirements = metadata['requirements'] || [] 203 | requirements.each do |req| 204 | next if req['optional'] 205 | next if req['external'] 206 | 207 | name = req['name'] 208 | groups = req['groups'] || [] 209 | 210 | version = gemify_version(req['version']) 211 | 212 | if groups.empty? or groups.include?('runtime') 213 | # populate runtime dependencies 214 | if gemspec.respond_to?(:add_runtime_dependency) 215 | gemspec.add_runtime_dependency(name,*version) 216 | else 217 | gemspec.add_dependency(name,*version) 218 | end 219 | else 220 | # populate development dependencies 221 | if gemspec.respond_to?(:add_development_dependency) 222 | gemspec.add_development_dependency(name,*version) 223 | else 224 | gemspec.add_dependency(name,*version) 225 | end 226 | end 227 | end 228 | 229 | # convert external dependencies into gemspec requirements 230 | requirements.each do |req| 231 | next unless req['external'] 232 | gemspec.requirements << ("%s-%s" % req.values_at('name', 'version')) 233 | end 234 | 235 | gemspec.homepage = homepage 236 | gemspec.require_paths = require_paths 237 | gemspec.post_install_message = metadata['install_message'] 238 | end 239 | 240 | # 241 | # Set gemspec settings that require a root directory path. 242 | # 243 | def to_gemspec_paths(gemspec) 244 | gemspec.files = files 245 | gemspec.extensions = extensions 246 | gemspec.executables = executables 247 | 248 | if Gem::VERSION < '1.7.' 249 | gemspec.default_executable = gemspec.executables.first 250 | end 251 | 252 | gemspec.test_files = glob_files(patterns[:test]) 253 | 254 | unless gemspec.files.include?('.document') 255 | gemspec.extra_rdoc_files = glob_files(patterns[:doc]) 256 | end 257 | end 258 | 259 | # 260 | # Return a copy of this file. This is used to generate a local 261 | # .gemspec file that can automatically read the index file. 262 | # 263 | def self.source_code 264 | File.read(__FILE__) 265 | end 266 | 267 | private 268 | 269 | def find_root 270 | root_files = patterns[:root] 271 | if Dir.glob(root_files).first 272 | Pathname.new(Dir.pwd) 273 | elsif Dir.glob("../#{root_files}").first 274 | Pathname.new(Dir.pwd).parent 275 | else 276 | #raise "Can't find root of project containing `#{root_files}'." 277 | warn "Can't find root of project containing `#{root_files}'." 278 | nil 279 | end 280 | end 281 | 282 | def glob(pattern) 283 | if File.directory?(pattern) 284 | Dir.glob(File.join(pattern, '**', '*')) 285 | else 286 | Dir.glob(pattern) 287 | end 288 | end 289 | 290 | def gemify_version(version) 291 | case version 292 | when /^(.*?)\+$/ 293 | ">= #{$1}" 294 | when /^(.*?)\-$/ 295 | "< #{$1}" 296 | when /^(.*?)\~$/ 297 | "~> #{$1}" 298 | else 299 | version 300 | end 301 | end 302 | 303 | end 304 | 305 | end 306 | 307 | Indexer::GemspecExporter.gemspec --------------------------------------------------------------------------------