Skip to content

Commit 83c147a

Browse files
committed
Implements #7
1 parent 24bb6b6 commit 83c147a

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

src/Console/Commands/Sync.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,19 @@
77

88
class Sync extends Command
99
{
10-
protected $signature = 'data:sync {--path=}';
10+
protected $signature = 'data:sync {--path=} {--model=}';
1111

1212
protected $description = 'Update Models with respective sync data files';
1313

1414
public function handle()
1515
{
1616
$path = $this->option('path');
17+
$model = $this->option('model');
1718

1819
$this->info('Updating Models with sync data files');
19-
(new Updater($path))->run();
20+
21+
(new Updater($path, $model))->run();
22+
2023
$this->comment('Data sync completed');
2124
}
2225
}

src/Updater.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,10 @@ class Updater
1313
*
1414
* @param string|null $path
1515
*/
16-
public function __construct($path = null)
16+
public function __construct($path = null, $model = null)
1717
{
18-
19-
$this->files = $this->getFiles(
20-
$this->getDirectory($path)
21-
);
18+
$directory = $this->getDirectory($path);
19+
$this->files = $this->getFiles($directory, $model);
2220
}
2321

2422
/**
@@ -84,8 +82,12 @@ protected function getDirectory($path)
8482
* @param string $directory
8583
* @return void
8684
*/
87-
protected function getFiles(string $directory)
85+
protected function getFiles(string $directory, string $model)
8886
{
87+
if($model) {
88+
return $directory . '/' . $model . '.json';
89+
}
90+
8991
return collect(File::files($directory))->map(function($path) {
9092
return $path->getPathname();
9193
})->toArray();

0 commit comments

Comments
 (0)