rails_age 0.5.3 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +39 -13
- data/README.md +246 -10
- data/config/initializers/types.rb +5 -5
- data/lib/apache_age/cypher.rb +95 -0
- data/lib/apache_age/entities/class_methods.rb +68 -38
- data/lib/apache_age/entities/edge.rb +2 -0
- data/lib/apache_age/entities/node.rb +3 -1
- data/lib/apache_age/entities/path.rb +27 -0
- data/lib/apache_age/entities/query_builder.rb +159 -0
- data/lib/apache_age/entities/vertex.rb +47 -47
- data/lib/apache_age/path.rb +4 -0
- data/lib/apache_age/types/{age_type_factory.rb → factory.rb} +3 -3
- data/lib/apache_age/validators/{vertex_type_validator copy.rb → node_type_validator.rb} +1 -1
- data/lib/apache_age/validators/unique_vertex.rb +27 -27
- data/lib/apache_age/validators/vertex_type_validator.rb +15 -0
- data/lib/generators/apache_age/edge/USAGE +7 -7
- data/lib/generators/apache_age/edge/edge_generator.rb +1 -0
- data/lib/generators/apache_age/generator_entity_helpers.rb +1 -9
- data/lib/generators/apache_age/node/USAGE +4 -4
- data/lib/generators/apache_age/node/node_generator.rb +1 -1
- data/lib/generators/apache_age/node/templates/node.rb.tt +2 -2
- data/lib/generators/apache_age/scaffold_edge/scaffold_edge_generator.rb +1 -2
- data/lib/generators/apache_age/scaffold_node/scaffold_node_generator.rb +1 -2
- data/lib/rails_age/version.rb +1 -1
- data/lib/rails_age.rb +5 -4
- data/lib/tasks/config_types.rake +6 -6
- metadata +25 -8
- data/lib/apache_age/types/age_type_generator.rb +0 -46
- data/lib/generators/apache_age/scaffold_edge/scaffold_node_generator.rb +0 -67
@@ -0,0 +1,27 @@
|
|
1
|
+
module ApacheAge
|
2
|
+
module Entities
|
3
|
+
module Path
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
include ActiveModel::Model
|
8
|
+
include ActiveModel::Dirty
|
9
|
+
include ActiveModel::Attributes
|
10
|
+
|
11
|
+
attribute :id, :integer
|
12
|
+
# attribute :label, :string
|
13
|
+
attribute :end_id, :integer
|
14
|
+
attribute :start_id, :integer
|
15
|
+
# override with a specific node type in the defining class
|
16
|
+
attribute :end_node
|
17
|
+
attribute :start_node
|
18
|
+
|
19
|
+
validates :end_node, :start_node, presence: true
|
20
|
+
validate :validate_nodes
|
21
|
+
|
22
|
+
extend ApacheAge::Entities::ClassMethods
|
23
|
+
include ApacheAge::Entities::CommonMethods
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,159 @@
|
|
1
|
+
# query =
|
2
|
+
# Person.
|
3
|
+
# cypher('age_schema')
|
4
|
+
# .match("(a:Person), (b:Person)")
|
5
|
+
# .where("a.name = 'Node A'", "b.name = 'Node B'")
|
6
|
+
# .return("a.name", "b.name")
|
7
|
+
# .as("name_a agtype, name_b agtype")
|
8
|
+
# .execute
|
9
|
+
# def cypher(graph_name = 'age_schema')
|
10
|
+
# ApacheAge::Cypher.new(graph_name)
|
11
|
+
# self
|
12
|
+
# end
|
13
|
+
|
14
|
+
module ApacheAge
|
15
|
+
module Entities
|
16
|
+
class QueryBuilder
|
17
|
+
attr_accessor :where_clauses, :order_clause, :limit_clause, :model_class, :match_clause,
|
18
|
+
:graph_name, :return_clause, :return_names, :return_variables
|
19
|
+
|
20
|
+
def initialize(model_class, graph_name: nil)
|
21
|
+
@model_class = model_class
|
22
|
+
@where_clauses = []
|
23
|
+
@return_names = ['find']
|
24
|
+
@return_clause = 'find'
|
25
|
+
@return_variables = []
|
26
|
+
@order_clause = nil
|
27
|
+
@limit_clause = nil
|
28
|
+
@match_clause = model_class.match_clause
|
29
|
+
@graph_name = graph_name || model_class.age_graph
|
30
|
+
end
|
31
|
+
|
32
|
+
# def cypher(graph_name = 'age_schema')
|
33
|
+
# return self if graph_name.blank?
|
34
|
+
|
35
|
+
# @graph_name = graph_name
|
36
|
+
# self
|
37
|
+
# end
|
38
|
+
|
39
|
+
def match(match_string)
|
40
|
+
@match_clause = match_string
|
41
|
+
self
|
42
|
+
end
|
43
|
+
|
44
|
+
# need to handle string inputs too: ie: "id(find) = #{id}"
|
45
|
+
def where(attributes)
|
46
|
+
return self if attributes.blank?
|
47
|
+
|
48
|
+
@where_clauses <<
|
49
|
+
if attributes.is_a?(String)
|
50
|
+
if attributes.include?('id(') || attributes.include?('find.')
|
51
|
+
attributes
|
52
|
+
else
|
53
|
+
"find.#{attributes}"
|
54
|
+
end
|
55
|
+
else
|
56
|
+
edge_keys = [:start_id, :start_node, :end_id, :end_node]
|
57
|
+
if edge_keys.any? { |key| attributes.include?(key) }
|
58
|
+
model_class.send(:where_edge_clause, attributes)
|
59
|
+
else
|
60
|
+
model_class.send(:where_node_clause, attributes)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
self
|
65
|
+
end
|
66
|
+
|
67
|
+
# New return method
|
68
|
+
def return(*variables)
|
69
|
+
return self if variables.blank?
|
70
|
+
|
71
|
+
@return_variables = variables
|
72
|
+
# @return_names = variables.empty? ? ['find'] : variables
|
73
|
+
# @return_clause = variables.empty? ? 'find' : "find.#{variables.join(', find.')}"
|
74
|
+
self
|
75
|
+
end
|
76
|
+
|
77
|
+
def order(ordering)
|
78
|
+
@order_clause = nil
|
79
|
+
return self if ordering.blank?
|
80
|
+
|
81
|
+
order_by_values = Array.wrap(ordering).map { |order| parse_ordering(order) }.join(', ')
|
82
|
+
@order_clause = "ORDER BY #{order_by_values}"
|
83
|
+
self
|
84
|
+
end
|
85
|
+
|
86
|
+
def limit(limit_value)
|
87
|
+
@limit_clause = "LIMIT #{limit_value}"
|
88
|
+
self
|
89
|
+
end
|
90
|
+
|
91
|
+
def all
|
92
|
+
cypher_sql = build_query
|
93
|
+
results = model_class.send(:execute_where, cypher_sql)
|
94
|
+
return results if return_variables.empty?
|
95
|
+
|
96
|
+
results.map(&:to_h).map { _1.slice(*return_variables) }
|
97
|
+
end
|
98
|
+
|
99
|
+
def execute
|
100
|
+
cypher_sql = build_query
|
101
|
+
model_class.send(:execute_sql, cypher_sql)
|
102
|
+
end
|
103
|
+
|
104
|
+
def first
|
105
|
+
cypher_sql = build_query(limit_clause || "LIMIT 1")
|
106
|
+
model_class.send(:execute_find, cypher_sql)
|
107
|
+
end
|
108
|
+
|
109
|
+
def to_sql
|
110
|
+
build_query.strip
|
111
|
+
end
|
112
|
+
|
113
|
+
private
|
114
|
+
|
115
|
+
def parse_ordering(ordering)
|
116
|
+
if ordering.is_a?(Hash)
|
117
|
+
# Convert hash into "find.key direction" format and join with commas
|
118
|
+
ordering = ordering.map { |k, v| "find.#{k} #{v}" }.join(', ')
|
119
|
+
elsif ordering.is_a?(Symbol)
|
120
|
+
# If it's a symbol, simply prepend "find."
|
121
|
+
ordering = "find.#{ordering}"
|
122
|
+
elsif ordering.is_a?(String)
|
123
|
+
# If it's a string, assume it's already in the correct format
|
124
|
+
ordering = ordering
|
125
|
+
elsif ordering.is_a?(Array)
|
126
|
+
# If it's an array, process each element recursively
|
127
|
+
ordering = ordering.map do |order|
|
128
|
+
if order.is_a?(Hash)
|
129
|
+
order.map { |k, v| "find.#{k} #{v}" }.join(', ')
|
130
|
+
elsif order.is_a?(Symbol)
|
131
|
+
"find.#{order}"
|
132
|
+
elsif order.is_a?(String)
|
133
|
+
order
|
134
|
+
else
|
135
|
+
raise ArgumentError, 'Array elements must be a string, symbol, or hash'
|
136
|
+
end
|
137
|
+
end.join(', ')
|
138
|
+
else
|
139
|
+
raise ArgumentError, 'Ordering must be a string, symbol, hash, or array'
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
def build_query(_extra_clause = nil)
|
144
|
+
where_sql = where_clauses.any? ? "WHERE #{where_clauses.join(' AND ')}" : ''
|
145
|
+
order_by = order_clause.present? ? order_clause : ''
|
146
|
+
<<-SQL.squish
|
147
|
+
SELECT *
|
148
|
+
FROM cypher('#{graph_name}', $$
|
149
|
+
MATCH #{match_clause}
|
150
|
+
#{where_sql}
|
151
|
+
RETURN #{return_clause}
|
152
|
+
#{order_clause}
|
153
|
+
#{limit_clause}
|
154
|
+
$$) AS (#{return_names.join(' agtype, ')} agtype);
|
155
|
+
SQL
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
@@ -1,53 +1,53 @@
|
|
1
|
-
module ApacheAge
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
# module ApacheAge
|
2
|
+
# module Entities
|
3
|
+
# module Vertex
|
4
|
+
# extend ActiveSupport::Concern
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
# included do
|
7
|
+
# include ActiveModel::Model
|
8
|
+
# include ActiveModel::Dirty
|
9
|
+
# include ActiveModel::Attributes
|
10
10
|
|
11
|
-
|
11
|
+
# attribute :id, :integer
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
# extend ApacheAge::Entities::ClassMethods
|
14
|
+
# include ApacheAge::Entities::CommonMethods
|
15
|
+
# end
|
16
16
|
|
17
|
-
|
17
|
+
# def age_type = 'vertex'
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
19
|
+
# # AgeSchema::Nodes::Company.create(company_name: 'Bedrock Quarry')
|
20
|
+
# # SELECT *
|
21
|
+
# # FROM cypher('age_schema', $$
|
22
|
+
# # CREATE (company:Company {company_name: 'Bedrock Quarry'})
|
23
|
+
# # RETURN company
|
24
|
+
# # $$) as (Company agtype);
|
25
|
+
# def create_sql
|
26
|
+
# alias_name = age_alias || age_label.downcase
|
27
|
+
# <<-SQL
|
28
|
+
# SELECT *
|
29
|
+
# FROM cypher('#{age_graph}', $$
|
30
|
+
# CREATE (#{alias_name}#{self})
|
31
|
+
# RETURN #{alias_name}
|
32
|
+
# $$) as (#{age_label} agtype);
|
33
|
+
# SQL
|
34
|
+
# end
|
35
35
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
end
|
36
|
+
# # So far just properties of string type with '' around them
|
37
|
+
# def update_sql
|
38
|
+
# alias_name = age_alias || age_label.downcase
|
39
|
+
# set_caluse =
|
40
|
+
# age_properties.map { |k, v| v ? "#{alias_name}.#{k} = '#{v}'" : "#{alias_name}.#{k} = NULL" }.join(', ')
|
41
|
+
# <<-SQL
|
42
|
+
# SELECT *
|
43
|
+
# FROM cypher('#{age_graph}', $$
|
44
|
+
# MATCH (#{alias_name}:#{age_label})
|
45
|
+
# WHERE id(#{alias_name}) = #{id}
|
46
|
+
# SET #{set_caluse}
|
47
|
+
# RETURN #{alias_name}
|
48
|
+
# $$) as (#{age_label} agtype);
|
49
|
+
# SQL
|
50
|
+
# end
|
51
|
+
# end
|
52
|
+
# end
|
53
|
+
# end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# lib/apache_age/types/
|
1
|
+
# lib/apache_age/types/factory.rb
|
2
2
|
# Automatically generates ActiveModel::Type classes
|
3
3
|
# Dynamically builds this (as a concrete example):
|
4
4
|
# module ApacheAge
|
@@ -22,8 +22,8 @@
|
|
22
22
|
# end
|
23
23
|
module ApacheAge
|
24
24
|
module Types
|
25
|
-
class
|
26
|
-
def self.
|
25
|
+
class Factory
|
26
|
+
def self.type_for(klass)
|
27
27
|
Class.new(ActiveModel::Type::Value) do
|
28
28
|
define_method(:cast) do |value|
|
29
29
|
case value
|
@@ -1,32 +1,32 @@
|
|
1
|
-
# lib/apache_age/validators/unique_vertex.rb
|
1
|
+
# # lib/apache_age/validators/unique_vertex.rb
|
2
2
|
|
3
|
-
# Usage (within an Age Model)
|
4
|
-
# validates_with(
|
5
|
-
# ApacheAge::Validators::UniqueVertex,
|
6
|
-
# attributes: [:first_name, :last_name, :gender]
|
7
|
-
# )
|
3
|
+
# # Usage (within an Age Model)
|
4
|
+
# # validates_with(
|
5
|
+
# # ApacheAge::Validators::UniqueVertex,
|
6
|
+
# # attributes: [:first_name, :last_name, :gender]
|
7
|
+
# # )
|
8
8
|
|
9
|
-
module ApacheAge
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
9
|
+
# module ApacheAge
|
10
|
+
# module Validators
|
11
|
+
# class UniqueVertex < ActiveModel::Validator
|
12
|
+
# def validate(record)
|
13
|
+
# allowed_keys = record.age_properties.keys
|
14
|
+
# attributes = options[:attributes]
|
15
|
+
# return if attributes.blank?
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
17
|
+
# record_attribs =
|
18
|
+
# attributes
|
19
|
+
# .map { |attr| [attr, record.send(attr)] }
|
20
|
+
# .to_h.symbolize_keys
|
21
|
+
# .slice(*allowed_keys)
|
22
|
+
# query = record.class.find_by(record_attribs)
|
23
23
|
|
24
|
-
|
25
|
-
|
24
|
+
# # if no match is found or if it finds itself, it's valid
|
25
|
+
# return if query.blank? || (query.id == record.id)
|
26
26
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
end
|
27
|
+
# record.errors.add(:base, 'record not unique')
|
28
|
+
# attributes.each { record.errors.add(_1, 'property combination not unique') }
|
29
|
+
# end
|
30
|
+
# end
|
31
|
+
# end
|
32
|
+
# end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# module ApacheAge
|
2
|
+
# module VertexTypeValidator
|
3
|
+
# def
|
4
|
+
# # Register the AGE typesvertex_attribute(attribute_name, type_symbol, klass)
|
5
|
+
# attribute attribute_name, type_symbol
|
6
|
+
|
7
|
+
# validate do
|
8
|
+
# value = send(attribute_name)
|
9
|
+
# unless value.is_a?(klass)
|
10
|
+
# errors.add(attribute_name, "must be a #{klass.name}")
|
11
|
+
# end
|
12
|
+
# end
|
13
|
+
# end
|
14
|
+
# end
|
15
|
+
# end
|
@@ -23,9 +23,9 @@ Example:
|
|
23
23
|
validates :employee_role, presence: true
|
24
24
|
validates :begin_date, presence: true
|
25
25
|
|
26
|
-
# unique
|
26
|
+
# unique edge validator (remove any attributes that are not important to uniqueness)
|
27
27
|
validates_with(
|
28
|
-
ApacheAge::Validators::
|
28
|
+
ApacheAge::Validators::UniqueEdge,
|
29
29
|
attributes: [:employee_role, :begin_date :start_node, :end_node]
|
30
30
|
)
|
31
31
|
end
|
@@ -35,12 +35,12 @@ Example:
|
|
35
35
|
`bin/rails g apache_age:edge Animals/Cat name age:integer`
|
36
36
|
|
37
37
|
This creates:
|
38
|
-
`app/
|
38
|
+
`app/edges/animals/has_cat.rb`
|
39
39
|
|
40
40
|
with the contents
|
41
41
|
```
|
42
|
-
class Animals::
|
43
|
-
include ApacheAge::Entities::
|
42
|
+
class Animals::HatCat
|
43
|
+
include ApacheAge::Entities::Edge
|
44
44
|
|
45
45
|
attribute :name, :string
|
46
46
|
attribute :age, :integer
|
@@ -48,9 +48,9 @@ Example:
|
|
48
48
|
validates :name, presence: true
|
49
49
|
validates :age, presence: true
|
50
50
|
|
51
|
-
# unique
|
51
|
+
# unique edge validator (remove any attributes that are not important to uniqueness)
|
52
52
|
validates_with(
|
53
|
-
ApacheAge::Validators::
|
53
|
+
ApacheAge::Validators::UniqueEdge,
|
54
54
|
attributes: [:name, :age, :start_node, :end_node]
|
55
55
|
)
|
56
56
|
end
|
@@ -14,6 +14,7 @@ module ApacheAge
|
|
14
14
|
|
15
15
|
source_root File.expand_path('templates', __dir__)
|
16
16
|
argument :attributes, type: :array, default: [], banner: "field:type field:type"
|
17
|
+
class_option :skip_namespace, type: :boolean, default: true, desc: "Skip namespace 'rails_age' in generated files"
|
17
18
|
|
18
19
|
def perform_task
|
19
20
|
age_type = 'edge'
|
@@ -40,14 +40,6 @@ module ApacheAge
|
|
40
40
|
end.join("\n") + "\n"
|
41
41
|
end
|
42
42
|
|
43
|
-
# def indented_end_namespace
|
44
|
-
# return '' if parent_module.empty?
|
45
|
-
|
46
|
-
# parent_module.split('::').map.with_index do |_, index|
|
47
|
-
# "#{' ' * (parent_module.split('::').length - 1 - index)}end"
|
48
|
-
# end.join("\n") + "\n"
|
49
|
-
# end
|
50
|
-
|
51
43
|
def add_type_config
|
52
44
|
return unless File.exist?(types_config_file)
|
53
45
|
|
@@ -79,7 +71,7 @@ module ApacheAge
|
|
79
71
|
<<-RUBY
|
80
72
|
require_dependency '#{file_path}'
|
81
73
|
ActiveModel::Type.register(
|
82
|
-
:#{type_name}, ApacheAge::Types::
|
74
|
+
:#{type_name}, ApacheAge::Types::Factory.type_for(#{entity_namespaced_class})
|
83
75
|
)
|
84
76
|
RUBY
|
85
77
|
end
|
@@ -12,7 +12,7 @@ Example:
|
|
12
12
|
with the contents:
|
13
13
|
```
|
14
14
|
class Cat
|
15
|
-
include ApacheAge::Entities::
|
15
|
+
include ApacheAge::Entities::Node
|
16
16
|
|
17
17
|
attribute :full_name, :string
|
18
18
|
attribute :birthdate, :date
|
@@ -22,7 +22,7 @@ Example:
|
|
22
22
|
|
23
23
|
# unique node validator (remove any attributes that are not important to uniqueness)
|
24
24
|
validates_with(
|
25
|
-
ApacheAge::Validators::
|
25
|
+
ApacheAge::Validators::UniqueNode,
|
26
26
|
attributes: [:full_name, :birthdate]
|
27
27
|
)
|
28
28
|
end
|
@@ -37,7 +37,7 @@ Example:
|
|
37
37
|
with the contents
|
38
38
|
```
|
39
39
|
class Animals::Cat
|
40
|
-
include ApacheAge::Entities::
|
40
|
+
include ApacheAge::Entities::Node
|
41
41
|
|
42
42
|
attribute :name, :string
|
43
43
|
attribute :age, :integer
|
@@ -47,7 +47,7 @@ Example:
|
|
47
47
|
|
48
48
|
# unique node validator (remove any attributes that are not important to uniqueness)
|
49
49
|
validates_with(
|
50
|
-
ApacheAge::Validators::
|
50
|
+
ApacheAge::Validators::UniqueNode,
|
51
51
|
attributes: [:name, :age]
|
52
52
|
)
|
53
53
|
end
|
@@ -9,9 +9,9 @@ module ApacheAge
|
|
9
9
|
include ApacheAge::GeneratorEntityHelpers
|
10
10
|
|
11
11
|
desc "Generates node (model) with attributes."
|
12
|
-
|
13
12
|
source_root File.expand_path('templates', __dir__)
|
14
13
|
argument :attributes, type: :array, default: [], banner: "field:type field:type"
|
14
|
+
class_option :skip_namespace, type: :boolean, default: true, desc: "Skip namespace 'rails_age' in generated files"
|
15
15
|
|
16
16
|
def perform_task
|
17
17
|
age_type = 'node'
|
@@ -1,5 +1,5 @@
|
|
1
1
|
class <%= class_name %>
|
2
|
-
include ApacheAge::Entities::
|
2
|
+
include ApacheAge::Entities::Node
|
3
3
|
|
4
4
|
<%- attributes_list.each do |attribute| -%>
|
5
5
|
attribute :<%= attribute[:name] %>, :<%= attribute[:type] %>
|
@@ -11,7 +11,7 @@ class <%= class_name %>
|
|
11
11
|
|
12
12
|
# custom unique node validator (remove any attributes that are NOT important to uniqueness)
|
13
13
|
validates_with(
|
14
|
-
ApacheAge::Validators::
|
14
|
+
ApacheAge::Validators::UniqueNode,
|
15
15
|
attributes: <%= unique_attributes.inspect %>
|
16
16
|
)
|
17
17
|
end
|
@@ -9,10 +9,9 @@ module ApacheAge
|
|
9
9
|
include Rails::Generators::ResourceHelpers
|
10
10
|
|
11
11
|
desc "Generates an edge, and its controller and views with the given attributes."
|
12
|
-
|
13
12
|
source_root File.expand_path("templates", __dir__)
|
14
|
-
|
15
13
|
argument :attributes, type: :array, default: [], banner: "field:type field:type"
|
14
|
+
class_option :skip_namespace, type: :boolean, default: true, desc: "Skip namespace 'rails_age' in generated files"
|
16
15
|
|
17
16
|
def create_model_file
|
18
17
|
invoke 'apache_age:edge', [name] + attributes.collect { |attr| "#{attr.name}:#{attr.type}" }
|
@@ -9,10 +9,9 @@ module ApacheAge
|
|
9
9
|
include Rails::Generators::ResourceHelpers
|
10
10
|
|
11
11
|
desc "Generates a node, and its controller and views with the given attributes."
|
12
|
-
|
13
12
|
source_root File.expand_path("templates", __dir__)
|
14
|
-
|
15
13
|
argument :attributes, type: :array, default: [], banner: "field:type field:type"
|
14
|
+
class_option :skip_namespace, type: :boolean, default: true, desc: "Skip namespace 'rails_age' in generated files"
|
16
15
|
|
17
16
|
def create_model_file
|
18
17
|
invoke 'apache_age:node', [name] + attributes.collect { |attr| "#{attr.name}:#{attr.type}" }
|
data/lib/rails_age/version.rb
CHANGED
data/lib/rails_age.rb
CHANGED
@@ -6,18 +6,19 @@ module RailsAge
|
|
6
6
|
end
|
7
7
|
|
8
8
|
module ApacheAge
|
9
|
+
require 'apache_age/cypher.rb'
|
10
|
+
require 'apache_age/entities/query_builder'
|
9
11
|
require 'apache_age/entities/class_methods'
|
10
12
|
require 'apache_age/entities/common_methods'
|
11
13
|
require 'apache_age/entities/entity'
|
12
|
-
require 'apache_age/entities/vertex'
|
13
14
|
require 'apache_age/entities/node'
|
14
15
|
require 'apache_age/entities/edge'
|
16
|
+
# require 'apache_age/entities/path'
|
15
17
|
require 'apache_age/node'
|
16
18
|
require 'apache_age/edge'
|
19
|
+
# require 'apache_age/path'
|
17
20
|
require 'apache_age/validators/expected_node_type'
|
18
21
|
require 'apache_age/validators/unique_node'
|
19
22
|
require 'apache_age/validators/unique_edge'
|
20
|
-
require 'apache_age/
|
21
|
-
require 'apache_age/types/age_type_factory'
|
22
|
-
require 'apache_age/types/age_type_generator'
|
23
|
+
require 'apache_age/types/factory'
|
23
24
|
end
|
data/lib/tasks/config_types.rake
CHANGED
@@ -5,28 +5,28 @@ namespace :apache_age do
|
|
5
5
|
desc "Install AGE types from rails_age into the rails initializers"
|
6
6
|
task :config_types => :environment do
|
7
7
|
types_file_path = File.expand_path("#{Rails.root}/config/initializers/types.rb", __FILE__)
|
8
|
-
required_file_path = "require 'apache_age/types/
|
8
|
+
required_file_path = "require 'apache_age/types/factory'"
|
9
9
|
required_file_content =
|
10
10
|
<<~RUBY
|
11
|
-
require 'apache_age/types/
|
11
|
+
require 'apache_age/types/factory'
|
12
12
|
# AGE Type Definition Usage (edges/nodes):
|
13
|
-
# require_dependency '
|
13
|
+
# require_dependency 'company'
|
14
14
|
# ActiveModel::Type.register(
|
15
|
-
# :company, ApacheAge::Types::
|
15
|
+
# :company, ApacheAge::Types::Factory.type_for(Company)
|
16
16
|
# )
|
17
17
|
RUBY
|
18
18
|
node_type_content =
|
19
19
|
<<-RUBY
|
20
20
|
require_dependency 'apache_age/node'
|
21
21
|
ActiveModel::Type.register(
|
22
|
-
:node, ApacheAge::Types::
|
22
|
+
:node, ApacheAge::Types::Factory.type_for(ApacheAge::Node)
|
23
23
|
)
|
24
24
|
RUBY
|
25
25
|
edge_type_content =
|
26
26
|
<<-RUBY
|
27
27
|
require_dependency 'apache_age/edge'
|
28
28
|
ActiveModel::Type.register(
|
29
|
-
:edge, ApacheAge::Types::
|
29
|
+
:edge, ApacheAge::Types::Factory.type_for(ApacheAge::Edge)
|
30
30
|
)
|
31
31
|
RUBY
|
32
32
|
|