lib/generators/apache_age/edge/templates/edge.rb.tt in rails_age-0.4.1 vs lib/generators/apache_age/edge/templates/edge.rb.tt in rails_age-0.5.0
- old
+ new
@@ -1,20 +1,28 @@
-<%= indented_namespace %>
-<%= ' ' * class_path.length %>class <%= class_name %>
-<%= ' ' * class_path.length %> include ApacheAge::Entities::Edge
+class <%= class_name %>
+ include ApacheAge::Entities::Edge
<%- attributes_list.each do |attribute| -%>
-<%= ' ' * class_path.length %> attribute :<%= attribute[:name] %>, :<%= attribute[:reference] || attribute[:type] %>
+ attribute :<%= attribute[:name] %>, :<%= attribute[:reference] || attribute[:type] %>
<%- end -%>
+ # recommendation for (start_node and end_node): change `:vertex` with the 'node' type
+ # see `config/initializers/apache_age.rb` for the list of available node types
+ attribute :start_node, :vertex
+ attribute :end_node, :vertex
-<%= ' ' * class_path.length %> validates :<%= unique_attributes.first %>, presence: true
-<%= ' ' * class_path.length %> validate :validate_unique
+<%- attributes_list.each do |attribute| -%>
+ validates :<%= attribute[:name] %>, presence: true
+<%- end -%>
+ validates :start_node, presence: true
+ validates :end_node, presence: true
-<%= ' ' * class_path.length %> private
+ validate :validate_unique_edge
-<%= ' ' * class_path.length %> def validate_unique
-<%= ' ' * class_path.length %> ApacheAge::Validators::UniqueEdgeValidator
-<%= ' ' * class_path.length %> .new(attributes: <%= unique_attributes.inspect %>)
-<%= ' ' * class_path.length %> .validate(self)
-<%= ' ' * class_path.length %> end
-<%= ' ' * class_path.length %>end
-<%= indented_end_namespace %>
+ private
+
+ # custom unique edge validator (remove any attributes that are NOT important to uniqueness)
+ def validate_unique_edge
+ ApacheAge::Validators::UniqueEdge
+ .new(attributes: <%= unique_edge_attributes.inspect %>)
+ .validate(self)
+ end
+end