Sha256: 57c7dea9724ae94fcde01506b75a6a07150bc28001a0409310e649ea10d158bd

Contents?: true

Size: 1.08 KB

Versions: 10

Compression:

Stored size: 1.08 KB

Contents

require 'active_support/hash_with_indifferent_access'

module DirModel
  module Export
    class AggregateDir
      include Utils

      attr_reader :export_dir_model_class, :context, :dir_path

      # @param [Export] export_model export model class
      def initialize(export_dir_model_class, context={})
        @export_dir_model_class = export_dir_model_class
        @context                = context.to_h.symbolize_keys
        @dir_path               = Dir.mktmpdir
      end

      # Add a row_model to the
      # @param [] source_model the source model of the export file model
      # @param [Hash] context the extra context given to the instance of the file model
      def append_model(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
      alias_method :<<, :append_model

      def generate
        yield self
        self
      end

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

    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
dir_model-0.6.2 lib/dir_model/export/aggregate_dir.rb
dir_model-0.6.1 lib/dir_model/export/aggregate_dir.rb
dir_model-0.6.0 lib/dir_model/export/aggregate_dir.rb
dir_model-0.5.2 lib/dir_model/export/aggregate_dir.rb
dir_model-0.5.1 lib/dir_model/export/aggregate_dir.rb
dir_model-0.5.0 lib/dir_model/export/aggregate_dir.rb
dir_model-0.4.0 lib/dir_model/export/aggregate_dir.rb
dir_model-0.3.4 lib/dir_model/export/aggregate_dir.rb
dir_model-0.3.3 lib/dir_model/export/aggregate_dir.rb
dir_model-0.3.2 lib/dir_model/export/aggregate_dir.rb