From 83c147ace9f9dca28bb41e88a60e1e166e85ae83 Mon Sep 17 00:00:00 2001 From: distinctm Date: Thu, 24 Jan 2019 17:27:30 -0500 Subject: [PATCH] Implements #7 --- src/Console/Commands/Sync.php | 7 +++++-- src/Updater.php | 14 ++++++++------ 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/Console/Commands/Sync.php b/src/Console/Commands/Sync.php index 55abfd0..a25b1c2 100644 --- a/src/Console/Commands/Sync.php +++ b/src/Console/Commands/Sync.php @@ -7,16 +7,19 @@ use Illuminate\Console\Command; class Sync extends Command { - protected $signature = 'data:sync {--path=}'; + protected $signature = 'data:sync {--path=} {--model=}'; protected $description = 'Update Models with respective sync data files'; public function handle() { $path = $this->option('path'); + $model = $this->option('model'); $this->info('Updating Models with sync data files'); - (new Updater($path))->run(); + + (new Updater($path, $model))->run(); + $this->comment('Data sync completed'); } } diff --git a/src/Updater.php b/src/Updater.php index e1ed17b..69e1f48 100644 --- a/src/Updater.php +++ b/src/Updater.php @@ -13,12 +13,10 @@ class Updater * * @param string|null $path */ - public function __construct($path = null) + public function __construct($path = null, $model = null) { - - $this->files = $this->getFiles( - $this->getDirectory($path) - ); + $directory = $this->getDirectory($path); + $this->files = $this->getFiles($directory, $model); } /** @@ -84,8 +82,12 @@ class Updater * @param string $directory * @return void */ - protected function getFiles(string $directory) + protected function getFiles(string $directory, string $model) { + if($model) { + return $directory . '/' . $model . '.json'; + } + return collect(File::files($directory))->map(function($path) { return $path->getPathname(); })->toArray();