rails_age 0.5.3 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cd10883497fc245765a9e8313265e4d06c7a602a2f83cad592ecb5a951ab488d
4
- data.tar.gz: ce03c6dc4535e2a54dddc9f2b9df8e4b413c6aeb690ee00138c4120fe1d72ce1
3
+ metadata.gz: 6777870b945c8684ea2ef5d10b8e7411259e002001b074754840a9422b594cee
4
+ data.tar.gz: '008ab62bbe28d408d390acd5e00cecc764507e21ae3d38ca94d219e9d299435f'
5
5
  SHA512:
6
- metadata.gz: dcb00b35abd3a931c95ffce304c079eee2d1ba1b09ee3aa17f9c9150f4bc3b55276e7670cf3925e4ae484a117bef66bddc0242efc0cbc8295da03538ae628805
7
- data.tar.gz: d6ac9aaa1ba0b04c9a48ed320e53a4de65a74e6cb6574f42c407b0c1124fafc650def68df4c41beaad27607b6f1fa22a7962518108c2fc39cd7c0e95f76d8c09
6
+ metadata.gz: 8a9c122ce1a8b5b173fc9ffd6ba45a4bf97965eb0681ec0d44e9779dcc1ef647da8e7e5110a5564a9f28c329ebe9e83ba832d920f4504bb5026650f41cc102d2
7
+ data.tar.gz: f9217b16e0177746a438ab5fed8a4e5c7f4bb6ff02b3e31a2a4d1db7a8bd246550e33be6494e0533c70dcbcde3a54078ed041b2c3a08718cb9b020c73353eee5
data/CHANGELOG.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Change Log
2
2
 
3
- ## VERSION 0.6.2 - 2024-xx-xx
3
+ ## VERSION 0.6.4 - 2024-xx-xx
4
4
 
5
5
  - **cypher queries** (like active record queries)
6
6
  * schema override
@@ -8,11 +8,11 @@
8
8
  * paths support
9
9
  * select attributes support
10
10
 
11
- ## VERSION 0.6.1 - 2024-xx-xx
11
+ ## VERSION 0.6.3 - 2024-xx-xx
12
12
 
13
13
  - **Age Path**
14
14
 
15
- ## VERSION 0.6.0 - 2024-xx-xx
15
+ ## VERSION 0.6.2 - 2024-xx-xx
16
16
 
17
17
  breaking change?: namespaces (by default) will use their own schema? (add to database.yml & schema.rb ?)
18
18
 
@@ -20,7 +20,7 @@ breaking change?: namespaces (by default) will use their own schema? (add to dat
20
20
 
21
21
  - **multiple AGE Schema**
22
22
 
23
- ## VERSION 0.5.4 - 2024-xx-xx
23
+ ## VERSION 0.6.1 - 2024-xx-xx
24
24
 
25
25
  - **Fix**
26
26
  * show validation errors in scaffold views
@@ -33,6 +33,16 @@ breaking change?: namespaces (by default) will use their own schema? (add to dat
33
33
  - **Edge Scaffold** (generates edge, type, view and controller)
34
34
  * add `rails generate apache_age:edge_scaffold HasJob employee_role start_node:person end_node:company`
35
35
 
36
+ ## VERSION 0.6.0 - 2024-06-xx
37
+
38
+ **breaking changes**: update naming
39
+ * renamed `Entities::Vertex` module to `Entities::Node`
40
+ * renamed `UniqueVertex` to `UniqueNode`
41
+ * rebamed `AgeTypeGenerator` to `Type::Factory`
42
+ * move `lib/generators/*` intp `lib/apache_age/generators`
43
+
44
+ here is the [commit](https://github.com/marpori/rails_age_demo_app/commit/a6f0708f2bbc165eddbafe63896068a72d803b17) to see the changes te demo app to make it work for release 0.6.0
45
+
36
46
  ## VERSION 0.5.3 - 2024-06-23
37
47
 
38
48
  - **Edge Scaffold** (generates edge, type, view and controller) - without start-/end-nodes types!?
data/README.md CHANGED
@@ -32,7 +32,7 @@ rails generate apache_age:scaffold_node Person first_name last_name
32
32
  rails generate apache_age:scaffold_edge HasJob employee_role start_date:date
33
33
  ```
34
34
 
35
- Ideally, edit the HasJob class so that `start_node` would use a type `:person` and the `end_node` uses at type `:company`
35
+ Ideally, edit the HasJob class so that `start_node` would use a type `:person` and the `end_node` uses at type `:company` - this is not yet supported by the generator, but easy to do manually as shown below. (The problem is that I havent been able to figure out how load all the rails types in the testing environment).
36
36
 
37
37
  ie:
38
38
  ```ruby
@@ -41,8 +41,8 @@ class HasJob
41
41
  include ApacheAge::Entities::Edge
42
42
 
43
43
  attribute :employee_role, :string
44
- attribute :start_node, :person # instead of `:node`
45
- attribute :end_node, :company # instead of `:node`
44
+ attribute :start_node, :person
45
+ attribute :end_node, :company
46
46
 
47
47
  validates :employee_role, presence: true
48
48
  validate :validate_unique_edge
@@ -1,20 +1,20 @@
1
1
  # config/initializers/types.rb
2
2
 
3
- require 'apache_age/types/age_type_factory'
3
+ require 'apache_age/types/factory'
4
4
  # USAGE (with edges or nodes) - ie:
5
- # require_dependency 'nodes/company'
5
+ # require_dependency 'company'
6
6
  # ActiveModel::Type.register(
7
- # :company, ApacheAge::Types::AgeTypeFactory.create_type_for(Nodes::Company)
7
+ # :company, ApacheAge::Types::Factory.type_for(Company)
8
8
  # )
9
9
 
10
10
  Rails.application.config.to_prepare do
11
11
  # Register AGE types
12
12
  require_dependency 'apache_age/node'
13
13
  ActiveModel::Type.register(
14
- :node, ApacheAge::Types::AgeTypeFactory.create_type_for(ApacheAge::Node)
14
+ :node, ApacheAge::Types::Factory.type_for(ApacheAge::Node)
15
15
  )
16
16
  require_dependency 'apache_age/edge'
17
17
  ActiveModel::Type.register(
18
- :edge, ApacheAge::Types::AgeTypeFactory.create_type_for(ApacheAge::Edge)
18
+ :edge, ApacheAge::Types::Factory.type_for(ApacheAge::Edge)
19
19
  )
20
20
  end
@@ -1,6 +1,6 @@
1
1
  module ApacheAge
2
2
  module Entities
3
- module Vertex
3
+ module Node
4
4
  extend ActiveSupport::Concern
5
5
 
6
6
  included do
@@ -1,53 +1,53 @@
1
- module ApacheAge
2
- module Entities
3
- module Node
4
- extend ActiveSupport::Concern
1
+ # module ApacheAge
2
+ # module Entities
3
+ # module Vertex
4
+ # extend ActiveSupport::Concern
5
5
 
6
- included do
7
- include ActiveModel::Model
8
- include ActiveModel::Dirty
9
- include ActiveModel::Attributes
6
+ # included do
7
+ # include ActiveModel::Model
8
+ # include ActiveModel::Dirty
9
+ # include ActiveModel::Attributes
10
10
 
11
- attribute :id, :integer
11
+ # attribute :id, :integer
12
12
 
13
- extend ApacheAge::Entities::ClassMethods
14
- include ApacheAge::Entities::CommonMethods
15
- end
13
+ # extend ApacheAge::Entities::ClassMethods
14
+ # include ApacheAge::Entities::CommonMethods
15
+ # end
16
16
 
17
- def age_type = 'vertex'
17
+ # def age_type = 'vertex'
18
18
 
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
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
- # 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
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/age_type_factory.rb
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 AgeTypeFactory
26
- def self.create_type_for(klass)
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,5 +1,5 @@
1
1
  module ApacheAge
2
- module VertexTypeValidator
2
+ module NodeTypeValidator
3
3
  def
4
4
  # Register the AGE typesvertex_attribute(attribute_name, type_symbol, klass)
5
5
  attribute attribute_name, type_symbol
@@ -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
- 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?
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
- 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)
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
- # if no match is found or if it finds itself, it's valid
25
- return if query.blank? || (query.id == record.id)
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
- 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
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 node validator (remove any attributes that are not important to uniqueness)
26
+ # unique edge validator (remove any attributes that are not important to uniqueness)
27
27
  validates_with(
28
- ApacheAge::Validators::UniqueVertex,
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/nodes/animals/cat.rb`
38
+ `app/edges/animals/has_cat.rb`
39
39
 
40
40
  with the contents
41
41
  ```
42
- class Animals::Cat
43
- include ApacheAge::Entities::Vertex
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 node validator (remove any attributes that are not important to uniqueness)
51
+ # unique edge validator (remove any attributes that are not important to uniqueness)
52
52
  validates_with(
53
- ApacheAge::Validators::UniqueVertex,
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::AgeTypeGenerator.create_type_for(#{entity_namespaced_class})
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::Vertex
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::UniqueVertex,
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::Vertex
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::UniqueVertex,
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::Vertex
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::UniqueVertex,
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}" }
@@ -1,3 +1,3 @@
1
1
  module RailsAge
2
- VERSION = '0.5.3'
2
+ VERSION = '0.6.0'
3
3
  end
data/lib/rails_age.rb CHANGED
@@ -9,7 +9,6 @@ module ApacheAge
9
9
  require 'apache_age/entities/class_methods'
10
10
  require 'apache_age/entities/common_methods'
11
11
  require 'apache_age/entities/entity'
12
- require 'apache_age/entities/vertex'
13
12
  require 'apache_age/entities/node'
14
13
  require 'apache_age/entities/edge'
15
14
  require 'apache_age/node'
@@ -17,7 +16,5 @@ module ApacheAge
17
16
  require 'apache_age/validators/expected_node_type'
18
17
  require 'apache_age/validators/unique_node'
19
18
  require 'apache_age/validators/unique_edge'
20
- require 'apache_age/validators/unique_vertex'
21
- require 'apache_age/types/age_type_factory'
22
- require 'apache_age/types/age_type_generator'
19
+ require 'apache_age/types/factory'
23
20
  end
@@ -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/age_type_generator'"
8
+ required_file_path = "require 'apache_age/types/factory'"
9
9
  required_file_content =
10
10
  <<~RUBY
11
- require 'apache_age/types/age_type_generator'
11
+ require 'apache_age/types/factory'
12
12
  # AGE Type Definition Usage (edges/nodes):
13
- # require_dependency 'nodes/company'
13
+ # require_dependency 'company'
14
14
  # ActiveModel::Type.register(
15
- # :company, ApacheAge::Types::AgeTypeGenerator.create_type_for(Nodes::Company)
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::AgeTypeGenerator.create_type_for(ApacheAge::Node)
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::AgeTypeGenerator.create_type_for(ApacheAge::Edge)
29
+ :edge, ApacheAge::Types::Factory.type_for(ApacheAge::Edge)
30
30
  )
31
31
  RUBY
32
32
 
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.5.3
4
+ version: 0.6.0
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-23 00:00:00.000000000 Z
11
+ date: 2024-06-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -104,13 +104,13 @@ files:
104
104
  - lib/apache_age/entities/node.rb
105
105
  - lib/apache_age/entities/vertex.rb
106
106
  - lib/apache_age/node.rb
107
- - lib/apache_age/types/age_type_factory.rb
108
- - lib/apache_age/types/age_type_generator.rb
107
+ - lib/apache_age/types/factory.rb
109
108
  - lib/apache_age/validators/expected_node_type.rb
109
+ - lib/apache_age/validators/node_type_validator.rb
110
110
  - lib/apache_age/validators/unique_edge.rb
111
111
  - lib/apache_age/validators/unique_node.rb
112
112
  - lib/apache_age/validators/unique_vertex.rb
113
- - lib/apache_age/validators/vertex_type_validator copy.rb
113
+ - lib/apache_age/validators/vertex_type_validator.rb
114
114
  - lib/generators/apache_age/edge/USAGE
115
115
  - lib/generators/apache_age/edge/edge_generator.rb
116
116
  - lib/generators/apache_age/edge/templates/edge.rb.tt
@@ -121,7 +121,6 @@ files:
121
121
  - lib/generators/apache_age/node/templates/node.rb.tt
122
122
  - lib/generators/apache_age/scaffold_edge/USAGE
123
123
  - lib/generators/apache_age/scaffold_edge/scaffold_edge_generator.rb
124
- - lib/generators/apache_age/scaffold_edge/scaffold_node_generator.rb
125
124
  - lib/generators/apache_age/scaffold_edge/templates/controller.rb.tt
126
125
  - lib/generators/apache_age/scaffold_edge/templates/views/_form.html.erb.tt
127
126
  - lib/generators/apache_age/scaffold_edge/templates/views/edit.html.erb.tt
@@ -1,46 +0,0 @@
1
- # lib/apache_age/types/age_type_generator.rb
2
- # Automatically generates ActiveModel::Type classes
3
- # Dynamically builds this (as a concrete example):
4
- # module ApacheAge
5
- # module Types
6
- # class CompanyType < ActiveModel::Type::Value
7
- # def cast(value)
8
- # case value
9
- # when Nodes::Company
10
- # value
11
- # when Hash
12
- # Nodes::Company.new(value)
13
- # else
14
- # nil
15
- # end
16
- # end
17
- # def serialize(value)
18
- # value.is_a?(Nodes::Company) ? value.attributes : nil
19
- # end
20
- # end
21
- # end
22
- # end
23
- module ApacheAge
24
- module Types
25
- class AgeTypeGenerator
26
- def self.create_type_for(klass)
27
- Class.new(ActiveModel::Type::Value) do
28
- define_method(:cast) do |value|
29
- case value
30
- when klass
31
- value
32
- when Hash
33
- klass.new(value)
34
- else
35
- nil
36
- end
37
- end
38
-
39
- define_method(:serialize) do |value|
40
- value.is_a?(klass) ? value.attributes : nil
41
- end
42
- end
43
- end
44
- end
45
- end
46
- end
@@ -1,67 +0,0 @@
1
- # lib/generators/apache_age/scaffold_node/scaffold_node_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 ScaffoldNodeGenerator < Rails::Generators::NamedBase
9
- include Rails::Generators::ResourceHelpers
10
-
11
- desc "Generates a node, and its controller and views with the given attributes."
12
-
13
- source_root File.expand_path("templates", __dir__)
14
-
15
- argument :attributes, type: :array, default: [], banner: "field:type field:type"
16
-
17
- def create_model_file
18
- invoke 'apache_age:edge', [name] + attributes.collect { |attr| "#{attr.name}:#{attr.type}" }
19
- end
20
-
21
- def create_controller_files
22
- template(
23
- "controller.rb.tt",
24
- File.join(Rails.root, "app/controllers", controller_class_path, "#{controller_file_name}_controller.rb")
25
- )
26
- end
27
-
28
- def create_route
29
- route_content = route_text(class_path, file_name)
30
- inject_into_file(
31
- File.join(Rails.root, 'config', 'routes.rb'), "\n#{route_content}",
32
- after: "Rails.application.routes.draw do"
33
- )
34
- end
35
-
36
- def copy_view_files
37
- available_views.each do |view|
38
- view_name = view == 'partial' ? "_#{singular_table_name}" : view
39
- filename = filename_with_extensions(view_name)
40
- template(
41
- "views/#{view}.html.erb.tt",
42
- File.join(Rails.root, "app/views", controller_file_path, filename)
43
- )
44
- end
45
- end
46
-
47
- private
48
-
49
- def available_views
50
- %w[index edit show new partial _form]
51
- end
52
-
53
- def filename_with_extensions(view)
54
- [view, :html, :erb].compact.join('.')
55
- end
56
-
57
- def route_text(class_path, file_name)
58
- return " resources :#{file_name.pluralize}" if class_path.empty?
59
-
60
- <<-RUBY
61
- namespace :#{class_path.join(':')} do
62
- resources :#{file_name.pluralize}
63
- end
64
- RUBY
65
- end
66
- end
67
- end