Skip to content

Commit

Permalink
move class methods to bottom
Browse files Browse the repository at this point in the history
  • Loading branch information
jordansissel committed Mar 8, 2012
1 parent e169ff0 commit 67e730d
Showing 1 changed file with 65 additions and 61 deletions.
126 changes: 65 additions & 61 deletions lib/fpm/package.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,65 +87,6 @@ class InvalidArgument < StandardError; end
# This is where you'd put rpm, deb, or other specific attributes.
attr_accessor :attributes

class << self
# This method is invoked when subclass occurs.
#
# Lets us track all known FPM::Package subclasses
def inherited(klass)
@subclasses ||= {}
@subclasses[klass.name.gsub(/.*:/, "").downcase] = klass
end # def self.inherited

# Get a list of all known package subclasses
def types
return @subclasses
end # def self.types

# This allows packages to define flags for the fpm command line
def option(flag, param, help, options={}, &block)
@options ||= []
if !flag.is_a?(Array)
flag = [flag]
end

flag = flag.collect { |f| "--#{type}-#{f.gsub(/^--/, "")}" }
help = "(#{type} only) #{help}"
@options << [flag, param, help, options, block]
end # def options

# Apply the options for this package on the clamp command
#
# Package flags become attributes '{type}-flag'
#
# So if you have:
#
# class Foo < FPM::Package
# option "--bar-baz" ...
# end
#
# The attribute value for --foo-bar-baz will be :foo_bar_baz"
def apply_options(clampcommand)
@options ||= []
@options.each do |args|
flag, param, help, options, block = args
clampcommand.option(flag, param, help, options) do |value|
# This is run in the scope of FPM::Command
value = block.call(value) unless block.nil?
# flag is an array, use the first flag as the attribute name
attr = flag.first[2..-1].gsub(/-+/, "_").to_sym
settings[attr] = value
end
end
end # def apply_options

# Get the type of this package class.
#
# For "Foo::Bar::BAZ" this will return "baz"
def type
self.name.split(':').last.downcase
end # def self.type
end # class << self

private

def initialize
Expand All @@ -169,9 +110,10 @@ def initialize
@maintainer = "<#{ENV["USER"]}@#{Socket.gethostname}>"
end

@name = nil
@architecture = "all"
@description = "no description given"
@version = 1.0
@version = "1.0"
@epoch = 1
@iteration = nil
@url = nil
Expand All @@ -190,7 +132,9 @@ def initialize
build_path
end # def initialize

# TODO [Jay]: make this better...?
# Get the 'type' for this instance.
#
# For FPM::Package::ABC, this returns 'abc'
def type
self.class.type
end # def type
Expand Down Expand Up @@ -319,4 +263,64 @@ def to_s(fmt="NAME.TYPE")
end # def to_s

public(:type, :initialize, :convert, :output, :input, :cleanup, :staging_path, :files, :to_s, :converted_from)

class << self
# This method is invoked when subclass occurs.
#
# Lets us track all known FPM::Package subclasses
def inherited(klass)
@subclasses ||= {}
@subclasses[klass.name.gsub(/.*:/, "").downcase] = klass
end # def self.inherited

# Get a list of all known package subclasses
def types
return @subclasses
end # def self.types

# This allows packages to define flags for the fpm command line
def option(flag, param, help, options={}, &block)
@options ||= []
if !flag.is_a?(Array)
flag = [flag]
end

flag = flag.collect { |f| "--#{type}-#{f.gsub(/^--/, "")}" }
help = "(#{type} only) #{help}"
@options << [flag, param, help, options, block]
end # def options

# Apply the options for this package on the clamp command
#
# Package flags become attributes '{type}-flag'
#
# So if you have:
#
# class Foo < FPM::Package
# option "--bar-baz" ...
# end
#
# The attribute value for --foo-bar-baz will be :foo_bar_baz"
def apply_options(clampcommand)
@options ||= []
@options.each do |args|
flag, param, help, options, block = args
clampcommand.option(flag, param, help, options) do |value|
# This is run in the scope of FPM::Command
value = block.call(value) unless block.nil?
# flag is an array, use the first flag as the attribute name
attr = flag.first[2..-1].gsub(/-+/, "_").to_sym
settings[attr] = value
end
end
end # def apply_options

# Get the type of this package class.
#
# For "Foo::Bar::BAZ" this will return "baz"
def type
self.name.split(':').last.downcase
end # def self.type
end # class << self

end # class FPM::Package

0 comments on commit 67e730d

Please sign in to comment.