Class: Kamaze::Project::Tools::Packager::Filesystem

Inherits:
Object
  • Object
show all
Defined in:
lib/kamaze/project/tools/packager/filesystem.rb,
lib/kamaze/project/tools/packager.rb

Overview

Filesystem description used during packaging

Filesystem has an Operator, which is intended to manipulate described files and directories. Package has a name, see package_name, package name SHOULD be constitued with two (path) parts. Package dirs are labeled, as a default, only :src is provided. Labels are used to constitute the complete directory path (relative to pwd).

Defined Under Namespace

Classes: Operator

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize {|_self| ... } ⇒ Filesystem

Returns a new instance of Filesystem.

Yields:

  • (_self)

Yield Parameters:



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/kamaze/project/tools/packager/filesystem.rb', line 56

def initialize
  @package_basedir = 'build'
  @package_name    = 'sample/package'

  @working_dir     = Dir.pwd
  @package_labels  = [:src]

  @verbose         = true
  @operator        = self.operator

  yield self if block_given?

  @source_files ||= []
  @purgeables   ||= []

  mute_attributes!(mutable_attributes)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



122
123
124
125
126
127
128
# File 'lib/kamaze/project/tools/packager/filesystem.rb', line 122

def method_missing(method, *args, &block)
  if respond_to_missing?(method)
    operator.public_send(method, *args, &block)
  else
    super
  end
end

Instance Attribute Details

#package_basedirPathname

Get packaging dir (root directory)

Returns:

  • (Pathname)


77
78
79
# File 'lib/kamaze/project/tools/packager/filesystem.rb', line 77

def package_basedir
  ::Pathname.new(@package_basedir)
end

#package_labels=(value) ⇒ Object (writeonly)

Labels for packaging stages



46
47
48
# File 'lib/kamaze/project/tools/packager/filesystem.rb', line 46

def package_labels=(value)
  @package_labels = value
end

#package_nameObject

Name given to the package



41
42
43
# File 'lib/kamaze/project/tools/packager/filesystem.rb', line 41

def package_name
  @package_name
end

#purgeables=(value) ⇒ Object (writeonly)

Labels for purgeables dirs (during prepare)



51
52
53
# File 'lib/kamaze/project/tools/packager/filesystem.rb', line 51

def purgeables=(value)
  @purgeables = value
end

#source_filesArray<Pathname>

Get source files

Returns:

  • (Array<Pathname>)


118
119
120
# File 'lib/kamaze/project/tools/packager/filesystem.rb', line 118

def source_files
  @source_files.sort.map { |path| ::Pathname.new(path) }
end

#verboseBoolean (protected)

Returns:

  • (Boolean)


157
158
159
# File 'lib/kamaze/project/tools/packager/filesystem.rb', line 157

def verbose
  @verbose
end

#working_dirPathname Also known as: pwd

Get (original) working dir

Returns:

  • (Pathname)


109
110
111
# File 'lib/kamaze/project/tools/packager/filesystem.rb', line 109

def working_dir
  ::Pathname.new(@working_dir)
end

Instance Method Details

#mutable_attribute?(attr) ⇒ Boolean

Returns:

  • (Boolean)


148
149
150
151
152
# File 'lib/kamaze/project/tools/packager/filesystem.rb', line 148

def mutable_attribute?(attr)
  attr = attr.to_s.gsub(/=$?/, '').to_sym

  mutable_attributes.include?(attr)
end

#mutable_attributesObject



136
137
138
139
140
141
142
143
144
145
146
# File 'lib/kamaze/project/tools/packager/filesystem.rb', line 136

def mutable_attributes
  [
    :verbose,
    :purgeables,
    :working_dir,
    :source_files,
    :package_basedir,
    :package_name,
    :package_labels
  ].sort
end

#mute_attributes!(attributes) ⇒ self (protected)

Pass some attributes to protected

Returns:

  • (self)


171
172
173
174
175
176
177
# File 'lib/kamaze/project/tools/packager/filesystem.rb', line 171

def mute_attributes!(attributes)
  attributes.each do |m|
    self.singleton_class.class_eval { protected "#{m}=" }
  end

  self
end

#operatorKamaze::Project::Tools::Packager::Filesystem::Operator (protected)

Get operator



162
163
164
165
166
# File 'lib/kamaze/project/tools/packager/filesystem.rb', line 162

def operator
  const_class = self.class.const_get(:Operator)

  const_class.new(self, verbose: verbose)
end

#package_dirPathname

Get package dir identified by its name

Returns:

  • (Pathname)


84
85
86
# File 'lib/kamaze/project/tools/packager/filesystem.rb', line 84

def package_dir
  package_basedir.join(package_name)
end

#package_dirsHash

Get (named) paths (as: src, tmp and bin)

Returns:

  • (Hash)


91
92
93
94
95
# File 'lib/kamaze/project/tools/packager/filesystem.rb', line 91

def package_dirs
  @package_labels.map do |k|
    [k, package_dir.join(k.to_s)]
  end.to_h
end

#purgeable_dirsHash

Get purgeable (named) paths

Returns:

  • (Hash)


100
101
102
103
104
# File 'lib/kamaze/project/tools/packager/filesystem.rb', line 100

def purgeable_dirs
  @purgeables.map do |k|
    [k, package_dirs[k]] if package_dirs[k]
  end.to_h
end

#respond_to_missing?(method, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


130
131
132
133
134
# File 'lib/kamaze/project/tools/packager/filesystem.rb', line 130

def respond_to_missing?(method, include_private = false)
  return true if operator.respond_to?(method, include_private)

  super(method, include_private)
end