Skip to content

Instantly share code, notes, and snippets.

@ancorgs
Created March 18, 2016 08:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ancorgs/a98597fa9a5e348eaaac to your computer and use it in GitHub Desktop.
Save ancorgs/a98597fa9a5e348eaaac to your computer and use it in GitHub Desktop.
query = DevicegraphQuery.new(a_devicegraph)
disk_query = query.disks # A DiskQuery object
disk_query = disk_query.with(name: ["/dev/sda", "/dev/sdb"]) # Another DiskQuery object
part_fine_query = disk_query.partitions.with(type: :primary) # A PartitionQuery object
part_query = query.partitions.with(name: ["/dev/sda2", "/dev/sdc3"])
# equivalent line
# part_query = PartitionQuery.new(a_devicegraph).with(name: ["/dev/sda2", "/dev/sdc3"])
# Calls to whatever.filesystems returns a FilesystemQuery object which is Enumerable
# So the equivalent to previous example (https://gist.github.com/ancorgs/9c628ef0f4fa717a2817) would be
query.filesystems.to_a # all file systems in the devicegraph
disk_query.filesystems.to_a # Filesystems in the chosen disks
part_fine_query.filesystems.to_a # fs in primary parts of chosen disks
part_query.filesystems.to_a # Filesystems in sda2 and sdc3
# But you don't need to use #to_a immediately (or at all)
disk_query.filesystems.map(&:label)
part_fine_query.filesystems.with(label: "bla").first
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment