Class: Sprout::FileTarget

Inherits:
Object
  • Object
show all
Defined in:
lib/sprout/file_target.rb

Overview

This is a class that is generally used by the Sprout::Specification::add_file_target method.

File targets are files that are embedded into (or referred to by) a RubyGem in such a way that Sprouts can use them as a library or executable.

A given FileTarget may be configured to work on a specific platform, or it may be universal.

Direct Known Subclasses

RemoteFileTarget

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (FileTarget) initialize {|_self| ... }

A new instance of FileTarget

Yields:

  • (_self)

Yield Parameters:



22
23
24
25
26
27
28
# File 'lib/sprout/file_target.rb', line 22

def initialize
  @executables = []
  @libraries   = []
  @load_path   = '.'
  @platform    = :universal
  yield self if block_given?
end

Instance Attribute Details

- (Object) executables (readonly)

Returns the value of attribute executables



19
20
21
# File 'lib/sprout/file_target.rb', line 19

def executables
  @executables
end

- (Object) libraries (readonly)

Returns the value of attribute libraries



20
21
22
# File 'lib/sprout/file_target.rb', line 20

def libraries
  @libraries
end

- (Object) load_path

Returns the value of attribute load_path



14
15
16
# File 'lib/sprout/file_target.rb', line 14

def load_path
  @load_path
end

- (Object) pkg_name

Returns the value of attribute pkg_name



15
16
17
# File 'lib/sprout/file_target.rb', line 15

def pkg_name
  @pkg_name
end

- (Object) pkg_version

Returns the value of attribute pkg_version



16
17
18
# File 'lib/sprout/file_target.rb', line 16

def pkg_version
  @pkg_version
end

- (Object) platform

Returns the value of attribute platform



17
18
19
# File 'lib/sprout/file_target.rb', line 17

def platform
  @platform
end

Instance Method Details

- (Object) add_executable(name, path)

Add an executable to the RubyGem package.

with this name.

Parameters:

  • (Symbol) name

    that will be used to retrieve this executable later.

  • (File) path

    relative path to the executable that will be associated



64
65
66
67
# File 'lib/sprout/file_target.rb', line 64

def add_executable name, path
  path = expand_local_path path
  executables << OpenStruct.new( :name => name, :path => path, :file_target => self )
end

- (Sprout::Library) add_library(name, path)

Add a library to the package.

Parameters:

  • (Symbol) name

    Name that will be used to retrieve this library on load.

  • (File, Path, Array) path

    File or files that will be associated with this library and copied into the target project library folder when loaded. (If the path is a directory, all files forward of that directory will be included.)

Returns:



46
47
48
49
50
51
52
53
54
55
# File 'lib/sprout/file_target.rb', line 46

def add_library name, path
  if path.is_a?(Array)
    path = path.collect { |p| expand_local_path(p) }
  else
    path = expand_local_path path
  end
  library = Sprout::Library.new( :name => name, :path => path, :file_target => self )
  libraries << library
  library
end

- (Object) expand_local_path(path)

This is a template method that is overridden by RemoteFileTarget.



81
82
83
# File 'lib/sprout/file_target.rb', line 81

def expand_local_path path
  File.join load_path, path
end

- (Object) resolve

This is a template method that will be called so that RemoteFileTarget subclasses and load the appropriate files at the appropriate time. Admittedly kind of smelly, other ideas welcome...



35
36
# File 'lib/sprout/file_target.rb', line 35

def resolve
end

- (Object) to_s



69
70
71
# File 'lib/sprout/file_target.rb', line 69

def to_s
  "[FileTarget pkg_name=#{pkg_name} pkg_version=#{pkg_version} platform=#{platform}]"
end

- (Object) validate



73
74
75
76
# File 'lib/sprout/file_target.rb', line 73

def validate
  raise Sprout::Errors::UsageError.new "FileTarget.pkg_name is required" if pkg_name.nil?
  raise Sprout::Errors::UsageError.new "FileTarget.pkg_version is required" if pkg_version.nil?
end