Class: Hadupils::Extensions::HiveSet

Inherits:
Object
  • Object
show all
Includes:
Hadupils::Extensions::Hive::AuxJarsPath
Defined in:
lib/hadupils/extensions/hive.rb

Overview

Collection class for filesystem-based Hive extensions

Pretty simple:

  • Given a #path in the filesystem

  • Scan that path for subdirectories

  • Wrap each subdirectory with Hadupils::Extensions::Hive.

  • Aggregate their hivercs and their auxiliary jars

See the Hadupils::Extensions::Hive class docs to understand the expectations per subdirectory. The #path provided to HiveSet should be a directory that contains subdirectories conforming to Hadupils::Extensions::Hive conventions.

All other files in the #path will be ignored; only subdirectories will be considered.

Member Extensions

The Array of Hadupils::Extensions::Hive instances derived from #path’s subdirectories will be available via the #members attribute reader.

The order of members matches the lexicographic order of their respective subdirectory basenames within #path.

The order of #hivercs and the order of #auxiliary_jars will follow the order of the respective #members. All of member 0’s #hivercs, followed by all of member 1’s #hivercs, and so on.

Thus the order of things is deterministic, according to lexicographic ordering of stuff in the filesystem. You control it in how you lay stuff out.

Good Advice

Don’t do anything stupid.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Hadupils::Extensions::Hive::AuxJarsPath

#hive_aux_jars_path

Constructor Details

#initialize(path) ⇒ HiveSet

Returns a new instance of HiveSet.



279
280
281
282
# File 'lib/hadupils/extensions/hive.rb', line 279

def initialize(path)
  @path = ::File.expand_path(path)
  @members = self.class.gather_member_extensions(@path)
end

Instance Attribute Details

#membersObject (readonly)

Returns the value of attribute members.



277
278
279
# File 'lib/hadupils/extensions/hive.rb', line 277

def members
  @members
end

#pathObject (readonly)

Returns the value of attribute path.



276
277
278
# File 'lib/hadupils/extensions/hive.rb', line 276

def path
  @path
end

Class Method Details

.gather_member_extensions(path) ⇒ Object



284
285
286
287
288
289
290
291
292
293
# File 'lib/hadupils/extensions/hive.rb', line 284

def self.gather_member_extensions(path)
  ::Dir.entries(path).sort.inject([]) do |result, entry|
    full_path = ::File.join(path, entry)
    if entry != '.' and entry != '..' and ::File.directory?(full_path)
      result << Hive.new(full_path)
    else
      result
    end
  end
end

Instance Method Details

#auxiliary_jarsObject

The cumulative Array of #auxiliary_jars across all #members, in member order.



303
304
305
# File 'lib/hadupils/extensions/hive.rb', line 303

def auxiliary_jars
  members_inject {|member| member.auxiliary_jars}
end

#hivercsObject

The cumulative Array of hive initialization file objects across all #members, in member order.



297
298
299
# File 'lib/hadupils/extensions/hive.rb', line 297

def hivercs
  members_inject {|member| member.hivercs}
end

#members_injectObject

Accumulate a list based on an operation (given in a block) per member. Accumulation is done against a starting empty list with the addition operator, not through appending. Therefore, the block needs to provide an array, not an arbitrary object.



311
312
313
314
315
316
# File 'lib/hadupils/extensions/hive.rb', line 311

def members_inject
  @members.inject [] do |result, member|
    increment = yield member
    result + increment
  end
end