LCOV - code coverage report
Current view: top level - lib/model/entity - entity_uri.dart (source / functions) Hit Total Coverage
Test: lcov.info Lines: 23 23 100.0 %
Date: 2021-10-20 14:50:35 Functions: 0 0 -

          Line data    Source code
       1             : part of apptive_grid_model;
       2             : 
       3             : /// A Uri representation used for performing Grid based Api Calls
       4             : class EntityUri extends ApptiveGridUri {
       5             :   /// Creates a new [EntityUri] based on known ids for [user], [space] and [grid]
       6           5 :   EntityUri({
       7             :     required this.user,
       8             :     required this.space,
       9             :     required this.grid,
      10             :     required this.entity,
      11             :   });
      12             : 
      13             :   /// Creates a new [EntityUri] based on a string [uri]
      14             :   /// Main usage of this is for [EntityUri] retrieved through other Api Calls
      15           4 :   factory EntityUri.fromUri(String uri) {
      16             :     const regex = r'/api/users/(\w+)/spaces/(\w+)/grids/(\w+)/entities/(\w+)\b';
      17           8 :     final matches = RegExp(regex).allMatches(uri);
      18          16 :     if (matches.isEmpty || matches.elementAt(0).groupCount != 4) {
      19           2 :       throw ArgumentError('Could not parse EntityUri $uri');
      20             :     }
      21           4 :     final match = matches.elementAt(0);
      22           4 :     return EntityUri(
      23           4 :       user: match.group(1)!,
      24           4 :       space: match.group(2)!,
      25           4 :       grid: match.group(3)!,
      26           4 :       entity: match.group(4)!,
      27             :     );
      28             :   }
      29             : 
      30             :   /// Id of the User that owns this Grid
      31             :   final String user;
      32             : 
      33             :   /// Id of the Space this Grid is in
      34             :   final String space;
      35             : 
      36             :   /// Id of the Grid this is in
      37             :   final String grid;
      38             : 
      39             :   /// Id of the Entity this [EntityUri] is representing
      40             :   final String entity;
      41             : 
      42           2 :   @override
      43             :   String toString() {
      44          10 :     return 'EntityUri(user: $user, space: $space grid: $grid, entity: $entity)';
      45             :   }
      46             : 
      47             :   /// Generates the uriString used for ApiCalls referencing this
      48           4 :   @override
      49             :   String get uriString =>
      50          20 :       '/api/users/$user/spaces/$space/grids/$grid/entities/$entity';
      51             : 
      52           4 :   @override
      53             :   bool operator ==(Object other) {
      54           4 :     return other is EntityUri &&
      55          12 :         entity == other.entity &&
      56          12 :         grid == other.grid &&
      57          12 :         user == other.user &&
      58          12 :         space == other.space;
      59             :   }
      60             : 
      61           1 :   @override
      62           2 :   int get hashCode => toString().hashCode;
      63             : }

Generated by: LCOV version 1.15