rails_age 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 272f8908dc8fb8a98adb443411e4b439eff914c8173b5eb64b53fa5362fa1572
4
- data.tar.gz: bf1921611698ffc1b651787f2e1b1a5d1bc503cbe1300639b2f9dada8202cdde
3
+ metadata.gz: dc953f22e786b1ce4280d8ced0bcb6ca768f89773c49a4ad0d7ddd3e3505e91e
4
+ data.tar.gz: fff1d2809ce6f439196bfbc8a50b7990453d17def541829ef332ee2711a7fd3a
5
5
  SHA512:
6
- metadata.gz: 51592c31e872a9b8dc6e96fe8fa42374241496e4da6a17ce70bf63f5f118ac078e81200259c048529e7e16b2147c8c5bbef00315cee8f26237295d04ffaea887
7
- data.tar.gz: 0b24560f7703e4dc4f97d3d36de626906a47a2cda5f5137cc6c1840a5281bbcf2693743666fb6301b26723c9723244bd1854c9c8b21d5d657eb621d4caf0d864
6
+ metadata.gz: e03cb391c29274953ab63badc3da19a9a965d53b23844086775d5668e61f32feba68605078b506c2a1ef8bde9d6627c67c087b7b1752acd2ccff681a55d4eec2
7
+ data.tar.gz: 6373605ea72f6d85babde6ba167135f3098bb6b04c60a56015a04670e48f40e452a2473ce974de2e5577d2930d267aff72e253fc0a1fe10f740def2b28c0cf1b
data/CHANGELOG.md CHANGED
@@ -9,11 +9,28 @@
9
9
  - **Paths**
10
10
  * ?
11
11
 
12
- ## VERSION 0.3.1 - 2024-xx-xx
12
+ ## VERSION 0.3.4 - 2024-xx-xx
13
+
14
+ - **Type Generators**
15
+ * add `rails generate apache_age:type`
16
+ * add `rails generate apache_age:node_type`
17
+ * add `rails generate apache_age:edge_type`
18
+
19
+ ## VERSION 0.3.3 - 2024-xx-xx
20
+
21
+ - **Edge Generator**
22
+ * add `rails generate apache_age:edge` to create an edge model
23
+
24
+
25
+ ## VERSION 0.3.2 - 2024-06-08
26
+
27
+ - **Node Generator**
28
+ * add `rails generate apache_age:node Pets/Cat name age:integer` creates a node with a namespace and attributes at: `app/nodes/pets/cat.rb`
29
+ * add `rails generate apache_age:node Cat name age:integer` creates a node with attributes at: `app/nodes/cat.rb`
30
+ * add `rails destroy apache_age:node Cat` deletes an existing node at: `app/nodes/cat.rb`
31
+
32
+ ## VERSION 0.3.1 - 2024-06-02
13
33
 
14
- - **Generators**
15
- * add `rails generate apache_age:node` to create a node model (with its type in initializer)
16
- * add `rails generate apache_age:edge` to create an edge model (with its type in initializer)
17
34
  - **Installer**
18
35
  * refactor into multiple independent tasks with tests
19
36
  - **Documentation**
data/README.md CHANGED
@@ -21,9 +21,13 @@ $ bundle
21
21
  $ bin/rails apache_age:install
22
22
  $ git add .
23
23
  $ git commit -m "Add Apache Age to Rails"
24
+ $ rails generate apache_age:node Company company_name
25
+ $ rails generate apache_age:node Person first_name last_name age:integer
24
26
  ```
25
27
 
26
- NOTE: it is important to commit the `db/schema.rb` to git because `rails db:migrate` inappropriately modifies the schema file (I haven't yet tested `db/structure.sql`). **You can run `bin/rails apache_age:install` at any time to repair the schema file as needed.**
28
+ NOTE: it is important to commit the `db/schema.rb` to git because `rails db:migrate` inappropriately modifies the schema file (I haven't yet tested `db/structure.sql`).
29
+
30
+ **You can run `bin/rails apache_age:install` at any time to repair the schema file as needed.**
27
31
 
28
32
  For now, if you are using `db/structure.sql` you will need to manually configure Apache Age (RailsAge) as described below.
29
33
 
@@ -202,9 +206,8 @@ module Nodes
202
206
  attribute :last_name, :string, default: nil
203
207
  attribute :given_name, :string, default: nil
204
208
  attribute :nick_name, :string, default: nil
205
- attribute :gender, :string, default: nil
206
209
 
207
- validates :gender, :first_name, :last_name, :given_name, :nick_name,
210
+ validates :first_name, :last_name, :given_name, :nick_name,
208
211
  presence: true
209
212
 
210
213
  def initialize(**attributes)
@@ -0,0 +1,54 @@
1
+ Description:
2
+ This creates Apache AGE nodes that work seamlessly with Rails.
3
+ A node can be created with or without a namespace.
4
+ See the below examples.
5
+
6
+ Example:
7
+ `bin/rails g apache_age:node Cat name age:integer`
8
+
9
+ This creates:
10
+ `app/nodes/cat.rb`
11
+
12
+ with the contents:
13
+ ```
14
+ class Cat
15
+ include ApacheAge::Entities::Vertex
16
+
17
+ attribute :name, :string
18
+ attribute :age, :integer
19
+
20
+ validates :name, presence: true
21
+ validates :age, presence: true
22
+
23
+ # unique node validator (remove any attributes that are not important to uniqueness)
24
+ validates_with(
25
+ ApacheAge::Validators::UniqueVertexValidator,
26
+ attributes: [:name, :age]
27
+ )
28
+ end
29
+ ```
30
+
31
+ A namespace can also be used:
32
+ `bin/rails g apache_age:node Animals/Cat name age:integer`
33
+
34
+ This creates:
35
+ `app/nodes/animals/cat.rb`
36
+
37
+ with the contents
38
+ ```
39
+ class Animals::Cat
40
+ include ApacheAge::Entities::Vertex
41
+
42
+ attribute :name, :string
43
+ attribute :age, :integer
44
+
45
+ validates :name, presence: true
46
+ validates :age, presence: true
47
+
48
+ # unique node validator (remove any attributes that are not important to uniqueness)
49
+ validates_with(
50
+ ApacheAge::Validators::UniqueVertexValidator,
51
+ attributes: [:name, :age]
52
+ )
53
+ end
54
+ ```
@@ -0,0 +1,56 @@
1
+ require 'rails/generators'
2
+ require 'rails/generators/named_base'
3
+
4
+ module ApacheAge
5
+ class EdgeGenerator < Rails::Generators::NamedBase
6
+ source_root File.expand_path('templates', __dir__)
7
+ argument :attributes, type: :array, default: [], banner: "field:type field:type"
8
+
9
+ def perform_task
10
+ behavior == :invoke ? create_edge_file : destroy_edge_file
11
+ end
12
+
13
+ private
14
+
15
+ def create_edge_file
16
+ template "edge.rb.tt", File.join("app/edge", class_path, "#{file_name}.rb")
17
+ end
18
+
19
+ def destroy_edge_file
20
+ file_path = File.join("app/edge", class_path, "#{file_name}.rb")
21
+ File.delete(file_path) if File.exist?(file_path)
22
+ end
23
+
24
+ def attributes_list
25
+ attributes.map { |attr| { name: attr.name, type: attr.type } }
26
+ end
27
+
28
+ def unique_attributes
29
+ attributes_list.map { |attr| attr[:name].to_sym }
30
+ end
31
+
32
+ def parent_module
33
+ class_path.map(&:camelize).join('::')
34
+ end
35
+
36
+ def full_class_name
37
+ parent_module.empty? ? class_name : "#{parent_module}::#{class_name}"
38
+ end
39
+
40
+ def indented_namespace
41
+ return '' if parent_module.empty?
42
+
43
+ parent_module.split('::').map.with_index do |namespace, index|
44
+ "#{' ' * index}module #{namespace}"
45
+ end.join("\n") + "\n"
46
+ end
47
+
48
+ def indented_end_namespace
49
+ return '' if parent_module.empty?
50
+
51
+ parent_module.split('::').map.with_index do |_, index|
52
+ "#{' ' * (parent_module.split('::').length - 1 - index)}end"
53
+ end.join("\n") + "\n"
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,20 @@
1
+ <%= indented_namespace %>
2
+ <%= ' ' * class_path.length %>class <%= class_name %>
3
+ <%= ' ' * class_path.length %> include ApacheAge::Entities::Edge
4
+
5
+ <%- attributes_list.each do |attribute| -%>
6
+ <%= ' ' * class_path.length %> attribute :<%= attribute[:name] %>, :<%= attribute[:reference] || attribute[:type] %>
7
+ <%- end -%>
8
+
9
+ <%= ' ' * class_path.length %> validates :<%= unique_attributes.first %>, presence: true
10
+ <%= ' ' * class_path.length %> validate :validate_unique
11
+
12
+ <%= ' ' * class_path.length %> private
13
+
14
+ <%= ' ' * class_path.length %> def validate_unique
15
+ <%= ' ' * class_path.length %> ApacheAge::Validators::UniqueEdgeValidator
16
+ <%= ' ' * class_path.length %> .new(attributes: <%= unique_attributes.inspect %>)
17
+ <%= ' ' * class_path.length %> .validate(self)
18
+ <%= ' ' * class_path.length %> end
19
+ <%= ' ' * class_path.length %>end
20
+ <%= indented_end_namespace %>
@@ -0,0 +1,54 @@
1
+ Description:
2
+ This creates Apache AGE nodes that work seamlessly with Rails.
3
+ A node can be created with or without a namespace.
4
+ See the below examples.
5
+
6
+ Example:
7
+ `bin/rails g apache_age:node Cat name age:integer`
8
+
9
+ This creates:
10
+ `app/nodes/cat.rb`
11
+
12
+ with the contents:
13
+ ```
14
+ class Cat
15
+ include ApacheAge::Entities::Vertex
16
+
17
+ attribute :name, :string
18
+ attribute :age, :integer
19
+
20
+ validates :name, presence: true
21
+ validates :age, presence: true
22
+
23
+ # unique node validator (remove any attributes that are not important to uniqueness)
24
+ validates_with(
25
+ ApacheAge::Validators::UniqueVertexValidator,
26
+ attributes: [:name, :age]
27
+ )
28
+ end
29
+ ```
30
+
31
+ A namespace can also be used:
32
+ `bin/rails g apache_age:node Animals/Cat name age:integer`
33
+
34
+ This creates:
35
+ `app/nodes/animals/cat.rb`
36
+
37
+ with the contents
38
+ ```
39
+ class Animals::Cat
40
+ include ApacheAge::Entities::Vertex
41
+
42
+ attribute :name, :string
43
+ attribute :age, :integer
44
+
45
+ validates :name, presence: true
46
+ validates :age, presence: true
47
+
48
+ # unique node validator (remove any attributes that are not important to uniqueness)
49
+ validates_with(
50
+ ApacheAge::Validators::UniqueVertexValidator,
51
+ attributes: [:name, :age]
52
+ )
53
+ end
54
+ ```
@@ -0,0 +1,56 @@
1
+ require 'rails/generators'
2
+ require 'rails/generators/named_base'
3
+
4
+ module ApacheAge
5
+ class NodeGenerator < Rails::Generators::NamedBase
6
+ source_root File.expand_path('templates', __dir__)
7
+ argument :attributes, type: :array, default: [], banner: "field:type field:type"
8
+
9
+ def perform_task
10
+ behavior == :invoke ? create_node_file : destroy_node_file
11
+ end
12
+
13
+ private
14
+
15
+ def create_node_file
16
+ template "node.rb.tt", File.join(destination_root, "app/nodes", class_path, "#{file_name}.rb")
17
+ end
18
+
19
+ def destroy_node_file
20
+ file_path = File.join(destination_root, "app/nodes", class_path, "#{file_name}.rb")
21
+ File.delete(file_path) if File.exist?(file_path)
22
+ end
23
+
24
+ def attributes_list
25
+ attributes.map { |attr| { name: attr.name, type: attr.type } }
26
+ end
27
+
28
+ def unique_attributes
29
+ attributes_list.map { |attr| attr[:name].to_sym }
30
+ end
31
+
32
+ def parent_module
33
+ class_path.map(&:camelize).join('::')
34
+ end
35
+
36
+ def full_class_name
37
+ parent_module.empty? ? class_name : "#{parent_module}::#{class_name}"
38
+ end
39
+
40
+ def indented_namespace
41
+ return '' if parent_module.empty?
42
+
43
+ parent_module.split('::').map.with_index do |namespace, index|
44
+ "#{' ' * index}module #{namespace}"
45
+ end.join("\n") + "\n"
46
+ end
47
+
48
+ def indented_end_namespace
49
+ return '' if parent_module.empty?
50
+
51
+ parent_module.split('::').map.with_index do |_, index|
52
+ "#{' ' * (parent_module.split('::').length - 1 - index)}end"
53
+ end.join("\n") + "\n"
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,17 @@
1
+ class <%= class_name %>
2
+ include ApacheAge::Entities::Vertex
3
+
4
+ <%- attributes_list.each do |attribute| -%>
5
+ attribute :<%= attribute[:name] %>, :<%= attribute[:type] %>
6
+ <%- end -%>
7
+
8
+ <%- attributes_list.each do |attribute| -%>
9
+ validates :<%= attribute[:name] %>, presence: true
10
+ <%- end -%>
11
+
12
+ # unique node validator (remove any attributes that are not important to uniqueness)
13
+ validates_with(
14
+ ApacheAge::Validators::UniqueVertexValidator,
15
+ attributes: <%= unique_attributes.inspect %>
16
+ )
17
+ end
@@ -1,3 +1,3 @@
1
1
  module RailsAge
2
- VERSION = '0.3.1'
2
+ VERSION = '0.3.2'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_age
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bill Tihen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-06-02 00:00:00.000000000 Z
11
+ date: 2024-06-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -76,6 +76,12 @@ files:
76
76
  - lib/apache_age/validators/unique_edge_validator.rb
77
77
  - lib/apache_age/validators/unique_vertex_validator.rb
78
78
  - lib/apache_age/validators/vertex_type_validator.rb
79
+ - lib/generators/apache_age/edge/USAGE
80
+ - lib/generators/apache_age/edge/edge_generator.rb
81
+ - lib/generators/apache_age/edge/templates/edge.rb.tt
82
+ - lib/generators/apache_age/node/USAGE
83
+ - lib/generators/apache_age/node/node_generator.rb
84
+ - lib/generators/apache_age/node/templates/node.rb.tt
79
85
  - lib/rails_age.rb
80
86
  - lib/rails_age/engine.rb
81
87
  - lib/rails_age/version.rb