Class: Purple::Script::PackageScript

Inherits:
Object
  • Object
show all
Defined in:
lib/purple/script.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cabinet) ⇒ PackageScript

Returns a new instance of PackageScript.



116
117
118
119
120
# File 'lib/purple/script.rb', line 116

def initialize cabinet
    @package = cabinet.create_package
    @cabinet = cabinet
    puts "DEBUG PackageScript#initialize: @package=#{@package}" if $DEBUG
end

Class Method Details

.callthrough(*ss) ⇒ Object



106
107
108
109
110
111
112
113
114
# File 'lib/purple/script.rb', line 106

def self.callthrough (*ss)
    ss.each do |s|
        module_eval <<-EOS
            def #{s} value
                @package.#{s} = value
            end
        EOS
    end
end

Instance Method Details

#file(filename) ⇒ Object



129
130
131
# File 'lib/purple/script.rb', line 129

def file filename
    pkg.files << filename
end

#inferObject



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
# File 'lib/purple/script.rb', line 133

def infer
    puts "DEBUG #infer" if $DEBUG
    puts "DEBUG PackageScript#infer: pkg=#{pkg}" if $DEBUG
    # Take a guess at the filename
    if 0 == pkg.files.size
        files = @cabinet.files
        puts "DEBUG #infer: cabinet_files=#{files.inspect}" if $DEBUG
        if 0 == files.size
            warn 'Cabinet files section is empty. Did you not specify any urls?'
        else
            if pkg.long_name
                # See if any filenames match the long name
                rs =  files.grep Regexp.new(Regexp.escape(pkg.long_name))
                file rs[0] if 1 == rs.size
            else
                # Else just guess that the first file is the right one
                file files[0]
            end
        end
    end

    puts "DEBUG #infer: pkg.files=#{pkg.files.inspect}" if $DEBUG
    puts "DEBUG #infer: long_name=#{pkg.long_name}" if $DEBUG
    # Take a guess at properties long_name, name, version, major, and minor
    md = Matches.match_filename pkg.files[0]
    puts "DEBUG #infer: filename match result  #{md.inspect}" if $DEBUG

    pkg.long_name = "#{md[:name]}-#{md[:version]}" if not pkg.long_name
    pkg.name = md[:name] if not pkg.name
    pkg.version = md[:version] if not pkg.version

    md = /^([0-9]+)\.([0-9]+).*/.match pkg.version
    pkg.major = md[1] if md and not pkg.major
    pkg.minor = md[2] if md and not pkg.minor
    
end

#pkgObject



125
126
127
# File 'lib/purple/script.rb', line 125

def pkg
    @package
end