Sha256: d6c13b90b3123b5d41382823bd88829471f256f437135dd289cb6e458b28db58
Contents?: true
Size: 1.27 KB
Versions: 1
Compression:
Stored size: 1.27 KB
Contents
# DirModel Import and export directories with an ORM-like interface. ## Installation Add this line to your application's Gemfile: ```ruby gem 'dir_model' ``` And then execute: $ bundle Or install it yourself as: $ gem install dir_model ## Usage ### Export ```ruby class ImageDir include DirModel file :image, path: -> { "#{dir}/#{sub_dir}" }, name: -> { "#{image_name}.png" } end class ImageExportDir < ImageDir include DirModel::Export def dir 'Sectors' end def sub_dir source_model.sector_name end def image_name source_model.zone_name end def image source_model.zone end end fixture_models = [ OpenStruct.new({ id: 42, sector_name: 'sector_name', zone_name: 'zone_name', zone: File.new('spec/fixtures/image.png'), }) ] exporter = DirModel::Export::AggregateDir.new(ImageExportDir) exporter.generate do |dir| models.each { |model| dir << model } end exporter.dir_path # => path of generated dir .../Sectors ``` ## zip_dir Use [`zip_dir`](https://github.com/FinalCAD/zip_dir) to zip DirModel::Export instances: ```ruby # Zip zipper = ZipDir::Zipper.new zip_file = zipper.generate do |z| z.add_and_cleanup_dir __dir_model_export__ end ``` **Ensure that `require zip_dir` occurs before `dir_model` (for now)**
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
dir_model-0.2.0 | README.md |