rails_age 0.5.2 → 0.6.0
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 +30 -10
- data/README.md +108 -57
- data/config/initializers/types.rb +20 -0
- data/lib/apache_age/edge.rb +5 -0
- data/lib/apache_age/entities/common_methods.rb +6 -0
- data/lib/apache_age/entities/edge.rb +4 -3
- data/lib/apache_age/entities/node.rb +53 -0
- data/lib/apache_age/entities/vertex.rb +47 -47
- data/lib/apache_age/node.rb +36 -0
- data/lib/apache_age/types/{age_type_generator.rb → factory.rb} +3 -3
- data/lib/apache_age/validators/expected_node_type.rb +17 -0
- data/lib/apache_age/validators/node_type_validator.rb +15 -0
- data/lib/apache_age/validators/unique_node.rb +32 -0
- data/lib/apache_age/validators/unique_vertex.rb +27 -27
- data/lib/apache_age/validators/vertex_type_validator.rb +14 -13
- 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/edge/templates/edge.rb.tt +3 -3
- data/lib/generators/apache_age/generator_entity_helpers.rb +6 -11
- 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/USAGE +16 -0
- data/lib/generators/apache_age/scaffold_edge/scaffold_edge_generator.rb +66 -0
- data/lib/generators/apache_age/scaffold_edge/templates/controller.rb.tt +50 -0
- data/lib/generators/apache_age/{scaffold_node/templates/views/_form.html.erb copy.tt → scaffold_edge/templates/views/_form.html.erb.tt} +10 -0
- data/lib/generators/apache_age/{scaffold_node/templates/views/index.html.erb copy.tt → scaffold_edge/templates/views/index.html.erb.tt} +1 -1
- data/lib/generators/apache_age/{scaffold_node/templates/views/partial.html.erb copy.tt → scaffold_edge/templates/views/partial.html.erb.tt} +11 -2
- data/lib/generators/apache_age/{scaffold_node/templates/views/show.html.erb copy.tt → scaffold_edge/templates/views/show.html.erb.tt} +1 -1
- data/lib/generators/apache_age/scaffold_node/scaffold_node_generator.rb +20 -22
- data/lib/rails_age/version.rb +1 -1
- data/lib/rails_age.rb +7 -4
- data/lib/tasks/config_types.rake +8 -8
- metadata +48 -10
- /data/lib/generators/apache_age/{scaffold_node/templates/views/edit.html.erb copy.tt → scaffold_edge/templates/views/edit.html.erb.tt} +0 -0
- /data/lib/generators/apache_age/{scaffold_node/templates/views/new.html.erb copy.tt → scaffold_edge/templates/views/new.html.erb.tt} +0 -0
- /data/lib/generators/apache_age/scaffold_node/templates/{node_controller.rb.tt → controller.rb.tt} +0 -0
@@ -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
|
@@ -1,14 +1,15 @@
|
|
1
|
-
module ApacheAge
|
2
|
-
|
3
|
-
|
4
|
-
|
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
|
5
6
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
end
|
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'
|
@@ -4,10 +4,10 @@ class <%= class_name %>
|
|
4
4
|
<%- attributes_list.each do |attribute| -%>
|
5
5
|
attribute :<%= attribute[:name] %>, :<%= attribute[:reference] || attribute[:type] %>
|
6
6
|
<%- end -%>
|
7
|
-
# recommendation for (start_node and end_node): change `:
|
7
|
+
# recommendation for (start_node and end_node): change `:node` with the actual 'node' type
|
8
8
|
# see `config/initializers/apache_age.rb` for the list of available node types
|
9
|
-
attribute :start_node
|
10
|
-
attribute :end_node
|
9
|
+
attribute :start_node
|
10
|
+
attribute :end_node
|
11
11
|
|
12
12
|
<%- attributes_list.each do |attribute| -%>
|
13
13
|
validates :<%= attribute[:name] %>, presence: true
|
@@ -3,12 +3,15 @@
|
|
3
3
|
module ApacheAge
|
4
4
|
module GeneratorEntityHelpers
|
5
5
|
def generate_age_entity(age_type)
|
6
|
-
template
|
6
|
+
template(
|
7
|
+
"#{age_type}.rb.tt",
|
8
|
+
File.join(Rails.root, "app/#{age_type}s", class_path, "#{file_name}.rb")
|
9
|
+
)
|
7
10
|
add_type_config
|
8
11
|
end
|
9
12
|
|
10
13
|
def destroy_age_entity(age_type)
|
11
|
-
file_path = File.join(
|
14
|
+
file_path = File.join(Rails.root, "app/#{age_type}s", class_path, "#{file_name}.rb")
|
12
15
|
File.delete(file_path) if File.exist?(file_path)
|
13
16
|
remove_type_config
|
14
17
|
end
|
@@ -37,14 +40,6 @@ module ApacheAge
|
|
37
40
|
end.join("\n") + "\n"
|
38
41
|
end
|
39
42
|
|
40
|
-
# def indented_end_namespace
|
41
|
-
# return '' if parent_module.empty?
|
42
|
-
|
43
|
-
# parent_module.split('::').map.with_index do |_, index|
|
44
|
-
# "#{' ' * (parent_module.split('::').length - 1 - index)}end"
|
45
|
-
# end.join("\n") + "\n"
|
46
|
-
# end
|
47
|
-
|
48
43
|
def add_type_config
|
49
44
|
return unless File.exist?(types_config_file)
|
50
45
|
|
@@ -76,7 +71,7 @@ module ApacheAge
|
|
76
71
|
<<-RUBY
|
77
72
|
require_dependency '#{file_path}'
|
78
73
|
ActiveModel::Type.register(
|
79
|
-
:#{type_name}, ApacheAge::Types::
|
74
|
+
:#{type_name}, ApacheAge::Types::Factory.type_for(#{entity_namespaced_class})
|
80
75
|
)
|
81
76
|
RUBY
|
82
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
|
@@ -0,0 +1,16 @@
|
|
1
|
+
Description:
|
2
|
+
Explain the generator
|
3
|
+
|
4
|
+
Example:
|
5
|
+
bin/rails generate apache_age:scaffold_edge HasPet careciver_role
|
6
|
+
|
7
|
+
This will create:
|
8
|
+
create app/edge/has_pet.rb
|
9
|
+
modified: config/initializers/types.rb
|
10
|
+
create app/controllers/has_pets_controller.rb
|
11
|
+
route resources :has_pets
|
12
|
+
create app/views/pets/index.html.erb
|
13
|
+
create app/views/pets/edit.html.erb
|
14
|
+
create app/views/pets/show.html.erb
|
15
|
+
create app/views/pets/new.html.erb
|
16
|
+
create app/views/pets/partial.html.erb
|
@@ -0,0 +1,66 @@
|
|
1
|
+
# lib/generators/apache_age/scaffold_edge/scaffold_edge_generator.rb
|
2
|
+
|
3
|
+
require 'rails/generators'
|
4
|
+
require 'rails/generators/named_base'
|
5
|
+
require 'rails/generators/resource_helpers'
|
6
|
+
|
7
|
+
module ApacheAge
|
8
|
+
class ScaffoldEdgeGenerator < Rails::Generators::NamedBase
|
9
|
+
include Rails::Generators::ResourceHelpers
|
10
|
+
|
11
|
+
desc "Generates an edge, and its controller and views with the given attributes."
|
12
|
+
source_root File.expand_path("templates", __dir__)
|
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
|
+
|
16
|
+
def create_model_file
|
17
|
+
invoke 'apache_age:edge', [name] + attributes.collect { |attr| "#{attr.name}:#{attr.type}" }
|
18
|
+
end
|
19
|
+
|
20
|
+
def create_controller_files
|
21
|
+
template(
|
22
|
+
"controller.rb.tt",
|
23
|
+
File.join(Rails.root, "app/controllers", controller_class_path, "#{controller_file_name}_controller.rb")
|
24
|
+
)
|
25
|
+
end
|
26
|
+
|
27
|
+
def create_route
|
28
|
+
route_content = route_text(class_path, file_name)
|
29
|
+
inject_into_file(
|
30
|
+
File.join(Rails.root, 'config', 'routes.rb'), "\n#{route_content}",
|
31
|
+
after: "Rails.application.routes.draw do"
|
32
|
+
)
|
33
|
+
end
|
34
|
+
|
35
|
+
def copy_view_files
|
36
|
+
available_views.each do |view|
|
37
|
+
view_name = view == 'partial' ? "_#{singular_table_name}" : view
|
38
|
+
filename = filename_with_extensions(view_name)
|
39
|
+
template(
|
40
|
+
"views/#{view}.html.erb.tt",
|
41
|
+
File.join(Rails.root, "app/views", controller_file_path, filename)
|
42
|
+
)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def available_views
|
49
|
+
%w[index edit show new partial _form]
|
50
|
+
end
|
51
|
+
|
52
|
+
def filename_with_extensions(view)
|
53
|
+
[view, :html, :erb].compact.join('.')
|
54
|
+
end
|
55
|
+
|
56
|
+
def route_text(class_path, file_name)
|
57
|
+
return " resources :#{file_name.pluralize}" if class_path.empty?
|
58
|
+
|
59
|
+
<<-RUBY
|
60
|
+
namespace :#{class_path.join(':')} do
|
61
|
+
resources :#{file_name.pluralize}
|
62
|
+
end
|
63
|
+
RUBY
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
class <%= controller_class_name %>Controller < ApplicationController
|
2
|
+
before_action :set_<%= singular_table_name %>, only: %i[show edit update destroy]
|
3
|
+
|
4
|
+
def index
|
5
|
+
@<%= plural_table_name %> = <%= class_name %>.all
|
6
|
+
end
|
7
|
+
|
8
|
+
def show
|
9
|
+
end
|
10
|
+
|
11
|
+
def new
|
12
|
+
@<%= singular_table_name %> = <%= class_name %>.new
|
13
|
+
end
|
14
|
+
|
15
|
+
def edit
|
16
|
+
end
|
17
|
+
|
18
|
+
def create
|
19
|
+
@<%= singular_table_name %> = <%= class_name %>.new(<%= singular_table_name %>_params)
|
20
|
+
|
21
|
+
if @<%= singular_table_name %>.save
|
22
|
+
redirect_to @<%= singular_table_name %>, notice: '<%= human_name %> was successfully created.'
|
23
|
+
else
|
24
|
+
render :new
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def update
|
29
|
+
if @<%= singular_table_name %>.update(<%= singular_table_name %>_params)
|
30
|
+
redirect_to @<%= singular_table_name %>, notice: '<%= human_name %> was successfully updated.'
|
31
|
+
else
|
32
|
+
render :edit
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def destroy
|
37
|
+
@<%= singular_table_name %>.destroy
|
38
|
+
redirect_to <%= index_helper %>_url, notice: '<%= human_name %> was successfully destroyed.'
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def set_<%= singular_table_name %>
|
44
|
+
@<%= singular_table_name %> = <%= class_name %>.find(params[:id])
|
45
|
+
end
|
46
|
+
|
47
|
+
def <%= singular_table_name %>_params
|
48
|
+
params.require(:<%= singular_table_name %>).permit(<%= (attributes + %i[start_id end_id]).map { |attr| ":#{attr.name}" }.join(', ') %>)
|
49
|
+
end
|
50
|
+
end
|
@@ -31,6 +31,16 @@
|
|
31
31
|
</div>
|
32
32
|
|
33
33
|
<% end -%>
|
34
|
+
<div>
|
35
|
+
<%%= form.label :start_node, style: "display: block" %>
|
36
|
+
<%%= form.collection_select(:start_id, ApacheAge::Node.all, :id, :display, prompt: 'Select a Start-Node') %>
|
37
|
+
</div>
|
38
|
+
|
39
|
+
<div>
|
40
|
+
<%%= form.label :end_node, style: "display: block" %>
|
41
|
+
<%%= form.collection_select(:end_id, ApacheAge::Node.all, :id, :display, prompt: 'Select an End-Node') %>
|
42
|
+
</div>
|
43
|
+
|
34
44
|
<div>
|
35
45
|
<%%= form.submit %>
|
36
46
|
</div>
|
@@ -6,7 +6,7 @@
|
|
6
6
|
|
7
7
|
<div id="<%= plural_table_name %>">
|
8
8
|
<%% @<%= plural_table_name %>.each do |<%= singular_table_name %>| %>
|
9
|
-
<%%= render <%= singular_table_name %> %>
|
9
|
+
<%%= render '<%= singular_table_name %>', <%= singular_table_name %>: <%= singular_table_name %> %>
|
10
10
|
<p>
|
11
11
|
<%%= link_to "Show this <%= human_name.downcase %>", <%= model_resource_name(singular_table_name) %> %>
|
12
12
|
</p>
|
@@ -5,8 +5,8 @@
|
|
5
5
|
<% if attribute.attachment? -%>
|
6
6
|
<%%= link_to <%= singular_table_name %>.<%= attribute.column_name %>.filename, <%= singular_table_name %>.<%= attribute.column_name %> if <%= singular_table_name %>.<%= attribute.column_name %>.attached? %>
|
7
7
|
<% elsif attribute.attachments? -%>
|
8
|
-
<%% <%= singular_table_name %>.<%= attribute.column_name %>.each do |<%= attribute.
|
9
|
-
<div><%%= link_to <%= attribute.
|
8
|
+
<%% <%= singular_table_name %>.<%= attribute.column_name %>.each do |<%= attribute.singular_name %>| %>
|
9
|
+
<div><%%= link_to <%= attribute.singular_name %>.filename, <%= attribute.singular_name %> %></div>
|
10
10
|
<%% end %>
|
11
11
|
<% else -%>
|
12
12
|
<%%= <%= singular_table_name %>.<%= attribute.column_name %> %>
|
@@ -14,4 +14,13 @@
|
|
14
14
|
</p>
|
15
15
|
|
16
16
|
<% end -%>
|
17
|
+
<p>
|
18
|
+
<strong>Start-Node:</strong>
|
19
|
+
<%%= <%= singular_table_name %>.start_node.display %>
|
20
|
+
</p>
|
21
|
+
|
22
|
+
<p>
|
23
|
+
<strong>End-Node:</strong>
|
24
|
+
<%%= <%= singular_table_name %>.end_node.display %>
|
25
|
+
</p>
|
17
26
|
</div>
|
@@ -1,6 +1,6 @@
|
|
1
1
|
<p style="color: green"><%%= notice %></p>
|
2
2
|
|
3
|
-
<%%= render @<%= singular_table_name %> %>
|
3
|
+
<%%= render '<%= singular_table_name %>', <%= singular_table_name %>: @<%= singular_table_name %> %>
|
4
4
|
|
5
5
|
<div>
|
6
6
|
<%%= link_to "Edit this <%= human_name.downcase %>", <%= edit_helper(type: :path) %> %> |
|
@@ -4,20 +4,14 @@ require 'rails/generators'
|
|
4
4
|
require 'rails/generators/named_base'
|
5
5
|
require 'rails/generators/resource_helpers'
|
6
6
|
|
7
|
-
require_relative '../generator_entity_helpers'
|
8
|
-
require_relative '../generator_resource_helpers'
|
9
|
-
|
10
7
|
module ApacheAge
|
11
8
|
class ScaffoldNodeGenerator < Rails::Generators::NamedBase
|
12
9
|
include Rails::Generators::ResourceHelpers
|
13
|
-
# include ApacheAge::GeneratorEntityHelpers
|
14
|
-
# include ApacheAge::GeneratorResourceHelpers
|
15
10
|
|
16
11
|
desc "Generates a node, and its controller and views with the given attributes."
|
17
|
-
|
18
12
|
source_root File.expand_path("templates", __dir__)
|
19
|
-
|
20
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"
|
21
15
|
|
22
16
|
def create_model_file
|
23
17
|
invoke 'apache_age:node', [name] + attributes.collect { |attr| "#{attr.name}:#{attr.type}" }
|
@@ -25,24 +19,27 @@ module ApacheAge
|
|
25
19
|
|
26
20
|
def create_controller_files
|
27
21
|
template(
|
28
|
-
"
|
29
|
-
File.join("app/controllers", controller_class_path, "#{controller_file_name}_controller.rb")
|
22
|
+
"controller.rb.tt",
|
23
|
+
File.join(Rails.root, "app/controllers", controller_class_path, "#{controller_file_name}_controller.rb")
|
30
24
|
)
|
31
25
|
end
|
32
26
|
|
33
27
|
def create_route
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
28
|
+
route_content = route_text(class_path, file_name)
|
29
|
+
inject_into_file(
|
30
|
+
File.join(Rails.root, 'config', 'routes.rb'), "\n#{route_content}",
|
31
|
+
after: "Rails.application.routes.draw do"
|
32
|
+
)
|
39
33
|
end
|
40
34
|
|
41
35
|
def copy_view_files
|
42
36
|
available_views.each do |view|
|
43
37
|
view_name = view == 'partial' ? "_#{singular_table_name}" : view
|
44
38
|
filename = filename_with_extensions(view_name)
|
45
|
-
template
|
39
|
+
template(
|
40
|
+
"views/#{view}.html.erb.tt",
|
41
|
+
File.join(Rails.root, "app/views", controller_file_path, filename)
|
42
|
+
)
|
46
43
|
end
|
47
44
|
end
|
48
45
|
|
@@ -56,13 +53,14 @@ module ApacheAge
|
|
56
53
|
[view, :html, :erb].compact.join('.')
|
57
54
|
end
|
58
55
|
|
59
|
-
def
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
56
|
+
def route_text(class_path, file_name)
|
57
|
+
return " resources :#{file_name.pluralize}" if class_path.empty?
|
58
|
+
|
59
|
+
<<-RUBY
|
60
|
+
namespace :#{class_path.join(':')} do
|
61
|
+
resources :#{file_name.pluralize}
|
62
|
+
end
|
63
|
+
RUBY
|
66
64
|
end
|
67
65
|
end
|
68
66
|
end
|
data/lib/rails_age/version.rb
CHANGED
data/lib/rails_age.rb
CHANGED
@@ -8,10 +8,13 @@ end
|
|
8
8
|
module ApacheAge
|
9
9
|
require 'apache_age/entities/class_methods'
|
10
10
|
require 'apache_age/entities/common_methods'
|
11
|
-
require 'apache_age/entities/edge'
|
12
11
|
require 'apache_age/entities/entity'
|
13
|
-
require 'apache_age/entities/
|
12
|
+
require 'apache_age/entities/node'
|
13
|
+
require 'apache_age/entities/edge'
|
14
|
+
require 'apache_age/node'
|
15
|
+
require 'apache_age/edge'
|
16
|
+
require 'apache_age/validators/expected_node_type'
|
17
|
+
require 'apache_age/validators/unique_node'
|
14
18
|
require 'apache_age/validators/unique_edge'
|
15
|
-
require 'apache_age/
|
16
|
-
require 'apache_age/types/age_type_generator'
|
19
|
+
require 'apache_age/types/factory'
|
17
20
|
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
|
-
require_dependency 'apache_age/
|
20
|
+
require_dependency 'apache_age/node'
|
21
21
|
ActiveModel::Type.register(
|
22
|
-
:
|
22
|
+
:node, ApacheAge::Types::Factory.type_for(ApacheAge::Node)
|
23
23
|
)
|
24
24
|
RUBY
|
25
25
|
edge_type_content =
|
26
26
|
<<-RUBY
|
27
|
-
require_dependency 'apache_age/
|
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
|
|