README.md in grumlin-0.19.7 vs README.md in grumlin-0.20.0
- old
+ new
@@ -141,10 +141,24 @@
.toList
end
end
```
+##### Overriding standard steps
+
+Sometimes it may be useful to override standard steps. Grumlin does not allow it by default, but one
+is still able to override standard steps if they know what they are doing:
+
+```ruby
+shortcut :addV, override: true do |label|
+ super(label).property(:default, :value)
+end
+```
+
+This will create a new shortcut that overrides the standard step `addV` and adds default properties to all vertices
+created by the repository that uses this shortcut.
+
#### Grumlin::Repository
`Grumlin::Repository` combines functionality of `Grumlin::Sugar` and `Grumlin::Shortcuts` as well as adds a few useful
shortcuts to make gremlin code more rubyish. Can be used as a drop in replacement for `Grumlin::Sugar`. Remember that
`Grumlin::Sugar` needs to be included, but `Grumlin::Repository` - extended. **Classes extending `Grumlin::Repository`
or `Grumlin::Shortcuts` can be inherited**, successors don't need to extend them again and have access to shortcuts
@@ -163,9 +177,26 @@
shortcut :red_triangles do |color|
# hasAll unwraps a hash of properties into a chain of `has` steps:
# hasAll(name1: :value, name2: :value) == has(:name1, :value).has(:name2, :value)
# the `props` shortcut does exactly the same but with `property` steps.
hasAll(T.label => :triangle, color: color)
+ end
+
+ # `default_vertex_properties` and `default_edge_properties`
+ # override `addV` and `addE` according and inject hashes returned from passed
+ # as properties for newly created vertices and edges.
+ # In case if a repository is inherited, newly defined default properties will be merged to
+ # default properties defined in the parent repository.
+ default_vertex_properties do |_label|
+ {
+ created_at: Time.now.to_i
+ }
+ end
+
+ default_edge_properties do |_label|
+ {
+ created_at: Time.now.to_i
+ }
end
# g and __ are already aware of shortcuts
query(:triangles_with_color, return_mode: :list) do |color| # :list is the default return mode, also possible: :none, :single, :traversal
g.V.hasLabel(:triangle)