README.md in dir_model-0.5.2 vs README.md in dir_model-0.6.0
- old
+ new
@@ -58,17 +58,21 @@
```ruby
class ChildImportDirModel
include DirModel::Model
include DirModel::Import
- file :metadata, regex: -> { /Zones\/Sector_(?<sector_id>.*)\/Zone_(?<zone_id>.*)\.(?<extension>json)/i }
+ file :metadata, regex: ->(foreign_value) { "Zones\/(?<sector_name>#{foreign_value})\/Zone_(?<zone_id>.*)\.(?<extension>json)" }
end
```
```ruby
class ParentImportDirModel < BasicImportDirModel
- has_one :dependency, ChildImportDirModel
+ has_one :dependency, ChildImportDirModel, foreign_key: :sector_name
+
+ def sector_name
+ "sector_#{sector_id}"
+ end
end
```
```ruby
parent_instance.dependency # => ChildImportDirModel
@@ -83,10 +87,10 @@
```ruby
class ZoneDirModel
include DirModel::Model
include DirModel::Import
- file :image, regex: ->(foreign_value) { "Zones\/#{foreign_value}\/Zone_(?<zone_id>.*)\.(?<extension>png|jpg)" }
+ file :image, regex: ->(foreign_value) { "Zones\/(?<sector_name>#{foreign_value})\/Zone_(?<zone_id>.*)\.(?<extension>png|jpg)" }
end
```
```ruby
class SectorDirModel