| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library descriptor.entry; | 5 library descriptor.entry; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import '../utils.dart'; | 9 import '../utils.dart'; |
| 10 import 'utils.dart'; | |
| 11 | 10 |
| 12 /// The base class for various declarative descriptions of filesystem entries. | 11 /// The base class for various declarative descriptions of filesystem entries. |
| 13 /// All asynchronous operations on descriptors are [schedule]d unless otherwise | 12 /// All asynchronous operations on descriptors are [schedule]d unless otherwise |
| 14 /// noted. | 13 /// noted. |
| 15 abstract class Entry { | 14 abstract class Entry { |
| 16 /// The name of this entry. For most operations, this must be a [String]; | 15 /// The name of this entry. |
| 17 /// however, if the entry will only be used for validation, it may be a | 16 final String name; |
| 18 /// non-[String] [Pattern]. In this case, there must be only one entry | |
| 19 /// matching it in the physical filesystem for validation to succeed. | |
| 20 final Pattern name; | |
| 21 | 17 |
| 22 Entry(this.name); | 18 Entry(this.name); |
| 23 | 19 |
| 24 /// Schedules the creation of the described entry within the [parent] | 20 /// Schedules the creation of the described entry within the [parent] |
| 25 /// directory. Returns a [Future] that completes after the creation is done. | 21 /// directory. Returns a [Future] that completes after the creation is done. |
| 26 /// | 22 /// |
| 27 /// [parent] defaults to [defaultRoot]. | 23 /// [parent] defaults to [defaultRoot]. |
| 28 Future create([String parent]); | 24 Future create([String parent]); |
| 29 | 25 |
| 30 /// Schedules the validation of the described entry. This validates that the | 26 /// Schedules the validation of the described entry. This validates that the |
| 31 /// physical file system under [parent] contains an entry that matches the one | 27 /// physical file system under [parent] contains an entry that matches the one |
| 32 /// described by [this]. Returns a [Future] that completes to `null` if the | 28 /// described by [this]. Returns a [Future] that completes to `null` if the |
| 33 /// entry is valid, or throws an error if it failed. | 29 /// entry is valid, or throws an error if it failed. |
| 34 /// | 30 /// |
| 35 /// [parent] defaults to [defaultRoot]. | 31 /// [parent] defaults to [defaultRoot]. |
| 36 Future validate([String parent]); | 32 Future validate([String parent]); |
| 37 | 33 |
| 34 /// An unscheduled version of [validate]. This is useful if validation errors |
| 35 /// need to be caught, since otherwise they'd be registered by the schedule. |
| 36 Future validateNow([String parent]); |
| 37 |
| 38 /// Treats [this] as an in-memory filesystem and returns a stream of the | 38 /// Treats [this] as an in-memory filesystem and returns a stream of the |
| 39 /// contents of the child entry located at [path]. This only works if [this] | 39 /// contents of the child entry located at [path]. This only works if [this] |
| 40 /// is a directory entry. This operation is not [schedule]d. | 40 /// is a directory entry. This operation is not [schedule]d. |
| 41 /// | 41 /// |
| 42 /// This method uses POSIX paths regardless of the underlying operating | 42 /// This method uses POSIX paths regardless of the underlying operating |
| 43 /// system. | 43 /// system. |
| 44 /// | 44 /// |
| 45 /// All errors in loading the file will be passed through the returned | 45 /// All errors in loading the file will be passed through the returned |
| 46 /// [Stream]. | 46 /// [Stream]. |
| 47 Stream<List<int>> load(String pathToLoad) => errorStream("Can't load " | 47 Stream<List<int>> load(String pathToLoad) => errorStream("Can't load " |
| 48 "'$pathToLoad' from within $nameDescription: not a directory."); | 48 "'$pathToLoad' from within '$name': not a directory."); |
| 49 | 49 |
| 50 /// Returns the contents of [this] as a stream. This only works if [this] is a | 50 /// Returns the contents of [this] as a stream. This only works if [this] is a |
| 51 /// file entry. This operation is not [schedule]d. | 51 /// file entry. This operation is not [schedule]d. |
| 52 /// | 52 /// |
| 53 /// All errors in loading the file will be passed through the returned | 53 /// All errors in loading the file will be passed through the returned |
| 54 /// [Stream]. | 54 /// [Stream]. |
| 55 Stream<List<int>> read(); | 55 Stream<List<int>> read(); |
| 56 | 56 |
| 57 /// Asserts that the name of the descriptor is a [String] and returns it. | |
| 58 String get stringName { | |
| 59 if (name is String) return name; | |
| 60 throw 'Pattern $nameDescription must be a string.'; | |
| 61 } | |
| 62 | |
| 63 /// Returns a human-readable description of [name], for error reporting. For | |
| 64 /// string names, this will just be the name in quotes; for regular | |
| 65 /// expressions, it will use JavaScript-style `/.../` notation. | |
| 66 String get nameDescription => describePattern(name); | |
| 67 | |
| 68 /// Returns a detailed tree-style description of [this]. | 57 /// Returns a detailed tree-style description of [this]. |
| 69 String describe(); | 58 String describe(); |
| 70 } | 59 } |
| OLD | NEW |