Class: DirModel::Export::AggregateDir

Inherits:
Object
  • Object
show all
Includes:
Utils
Defined in:
lib/dir_model/export/aggregate_dir.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils

#mkdir

Constructor Details

#initialize(context = {}) ⇒ AggregateDir

Returns a new instance of AggregateDir.

Parameters:

  • export_model (Export)

    export model class



11
12
13
14
# File 'lib/dir_model/export/aggregate_dir.rb', line 11

def initialize(context={})
  @context  = context.to_h.symbolize_keys
  @dir_path = Dir.mktmpdir
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



8
9
10
# File 'lib/dir_model/export/aggregate_dir.rb', line 8

def context
  @context
end

#dir_pathObject (readonly)

Returns the value of attribute dir_path.



8
9
10
# File 'lib/dir_model/export/aggregate_dir.rb', line 8

def dir_path
  @dir_path
end

Instance Method Details

#append_model(export_dir_model_class, source_model, context = {}) ⇒ Object

Add a row_model to the

Parameters:

  • []

    source_model the source model of the export file model

  • context (Hash) (defaults to: {})

    the extra context given to the instance of the file model



19
20
21
22
# File 'lib/dir_model/export/aggregate_dir.rb', line 19

def append_model(export_dir_model_class, source_model, context={})
  source_path = export_dir_model_class.new(source_model, context.reverse_merge(self.context)).path
  FileUtils.cp_r Dir.glob("#{source_path}/*"), dir_path
end

#filesObject



29
30
31
# File 'lib/dir_model/export/aggregate_dir.rb', line 29

def files
  Dir["#{@dir_path}/**/*"].select { |f| File.file?(f) }
end

#generate {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:



24
25
26
27
# File 'lib/dir_model/export/aggregate_dir.rb', line 24

def generate
  yield self
  self
end