activegraph 11.0.0.beta.1-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +2016 -0
- data/CONTRIBUTORS +12 -0
- data/Gemfile +24 -0
- data/README.md +111 -0
- data/activegraph.gemspec +52 -0
- data/bin/rake +17 -0
- data/config/locales/en.yml +5 -0
- data/config/neo4j/add_classnames.yml +1 -0
- data/config/neo4j/config.yml +35 -0
- data/lib/active_graph.rb +123 -0
- data/lib/active_graph/ansi.rb +14 -0
- data/lib/active_graph/attribute_set.rb +32 -0
- data/lib/active_graph/base.rb +77 -0
- data/lib/active_graph/class_arguments.rb +39 -0
- data/lib/active_graph/config.rb +135 -0
- data/lib/active_graph/core.rb +14 -0
- data/lib/active_graph/core/connection_failed_error.rb +6 -0
- data/lib/active_graph/core/cypher_error.rb +37 -0
- data/lib/active_graph/core/entity.rb +11 -0
- data/lib/active_graph/core/instrumentable.rb +37 -0
- data/lib/active_graph/core/label.rb +135 -0
- data/lib/active_graph/core/logging.rb +44 -0
- data/lib/active_graph/core/node.rb +15 -0
- data/lib/active_graph/core/querable.rb +41 -0
- data/lib/active_graph/core/query.rb +485 -0
- data/lib/active_graph/core/query_builder.rb +18 -0
- data/lib/active_graph/core/query_clauses.rb +727 -0
- data/lib/active_graph/core/query_ext.rb +24 -0
- data/lib/active_graph/core/query_find_in_batches.rb +46 -0
- data/lib/active_graph/core/record.rb +51 -0
- data/lib/active_graph/core/result.rb +31 -0
- data/lib/active_graph/core/schema.rb +65 -0
- data/lib/active_graph/core/schema_errors.rb +12 -0
- data/lib/active_graph/core/wrappable.rb +30 -0
- data/lib/active_graph/errors.rb +59 -0
- data/lib/active_graph/lazy_attribute_hash.rb +38 -0
- data/lib/active_graph/migration.rb +148 -0
- data/lib/active_graph/migrations.rb +27 -0
- data/lib/active_graph/migrations/base.rb +77 -0
- data/lib/active_graph/migrations/check_pending.rb +20 -0
- data/lib/active_graph/migrations/helpers.rb +105 -0
- data/lib/active_graph/migrations/helpers/id_property.rb +72 -0
- data/lib/active_graph/migrations/helpers/relationships.rb +66 -0
- data/lib/active_graph/migrations/helpers/schema.rb +63 -0
- data/lib/active_graph/migrations/migration_file.rb +24 -0
- data/lib/active_graph/migrations/runner.rb +195 -0
- data/lib/active_graph/migrations/schema.rb +64 -0
- data/lib/active_graph/migrations/schema_migration.rb +14 -0
- data/lib/active_graph/model_schema.rb +139 -0
- data/lib/active_graph/node.rb +110 -0
- data/lib/active_graph/node/callbacks.rb +8 -0
- data/lib/active_graph/node/dependent.rb +11 -0
- data/lib/active_graph/node/dependent/association_methods.rb +49 -0
- data/lib/active_graph/node/dependent/query_proxy_methods.rb +52 -0
- data/lib/active_graph/node/dependent_callbacks.rb +31 -0
- data/lib/active_graph/node/enum.rb +26 -0
- data/lib/active_graph/node/has_n.rb +602 -0
- data/lib/active_graph/node/has_n/association.rb +278 -0
- data/lib/active_graph/node/has_n/association/rel_factory.rb +61 -0
- data/lib/active_graph/node/has_n/association/rel_wrapper.rb +23 -0
- data/lib/active_graph/node/has_n/association_cypher_methods.rb +108 -0
- data/lib/active_graph/node/id_property.rb +224 -0
- data/lib/active_graph/node/id_property/accessor.rb +62 -0
- data/lib/active_graph/node/initialize.rb +21 -0
- data/lib/active_graph/node/labels.rb +207 -0
- data/lib/active_graph/node/labels/index.rb +37 -0
- data/lib/active_graph/node/labels/reloading.rb +21 -0
- data/lib/active_graph/node/node_list_formatter.rb +13 -0
- data/lib/active_graph/node/node_wrapper.rb +54 -0
- data/lib/active_graph/node/orm_adapter.rb +82 -0
- data/lib/active_graph/node/persistence.rb +186 -0
- data/lib/active_graph/node/property.rb +60 -0
- data/lib/active_graph/node/query.rb +76 -0
- data/lib/active_graph/node/query/query_proxy.rb +367 -0
- data/lib/active_graph/node/query/query_proxy_eager_loading.rb +177 -0
- data/lib/active_graph/node/query/query_proxy_eager_loading/association_tree.rb +75 -0
- data/lib/active_graph/node/query/query_proxy_enumerable.rb +110 -0
- data/lib/active_graph/node/query/query_proxy_find_in_batches.rb +19 -0
- data/lib/active_graph/node/query/query_proxy_link.rb +139 -0
- data/lib/active_graph/node/query/query_proxy_methods.rb +303 -0
- data/lib/active_graph/node/query/query_proxy_methods_of_mass_updating.rb +99 -0
- data/lib/active_graph/node/query_methods.rb +68 -0
- data/lib/active_graph/node/reflection.rb +86 -0
- data/lib/active_graph/node/rels.rb +11 -0
- data/lib/active_graph/node/scope.rb +166 -0
- data/lib/active_graph/node/unpersisted.rb +48 -0
- data/lib/active_graph/node/validations.rb +59 -0
- data/lib/active_graph/paginated.rb +27 -0
- data/lib/active_graph/railtie.rb +108 -0
- data/lib/active_graph/relationship.rb +68 -0
- data/lib/active_graph/relationship/callbacks.rb +21 -0
- data/lib/active_graph/relationship/initialize.rb +28 -0
- data/lib/active_graph/relationship/persistence.rb +133 -0
- data/lib/active_graph/relationship/persistence/query_factory.rb +95 -0
- data/lib/active_graph/relationship/property.rb +92 -0
- data/lib/active_graph/relationship/query.rb +99 -0
- data/lib/active_graph/relationship/rel_wrapper.rb +31 -0
- data/lib/active_graph/relationship/related_node.rb +87 -0
- data/lib/active_graph/relationship/types.rb +80 -0
- data/lib/active_graph/relationship/validations.rb +8 -0
- data/lib/active_graph/schema/operation.rb +102 -0
- data/lib/active_graph/shared.rb +48 -0
- data/lib/active_graph/shared/attributes.rb +217 -0
- data/lib/active_graph/shared/callbacks.rb +66 -0
- data/lib/active_graph/shared/cypher.rb +37 -0
- data/lib/active_graph/shared/declared_properties.rb +204 -0
- data/lib/active_graph/shared/declared_property.rb +109 -0
- data/lib/active_graph/shared/declared_property/index.rb +37 -0
- data/lib/active_graph/shared/enum.rb +167 -0
- data/lib/active_graph/shared/filtered_hash.rb +79 -0
- data/lib/active_graph/shared/identity.rb +34 -0
- data/lib/active_graph/shared/initialize.rb +65 -0
- data/lib/active_graph/shared/marshal.rb +23 -0
- data/lib/active_graph/shared/mass_assignment.rb +63 -0
- data/lib/active_graph/shared/permitted_attributes.rb +28 -0
- data/lib/active_graph/shared/persistence.rb +272 -0
- data/lib/active_graph/shared/property.rb +249 -0
- data/lib/active_graph/shared/query_factory.rb +122 -0
- data/lib/active_graph/shared/rel_type_converters.rb +43 -0
- data/lib/active_graph/shared/serialized_properties.rb +30 -0
- data/lib/active_graph/shared/type_converters.rb +439 -0
- data/lib/active_graph/shared/typecasted_attributes.rb +99 -0
- data/lib/active_graph/shared/typecaster.rb +53 -0
- data/lib/active_graph/shared/validations.rb +44 -0
- data/lib/active_graph/tasks/migration.rake +204 -0
- data/lib/active_graph/timestamps.rb +11 -0
- data/lib/active_graph/timestamps/created.rb +9 -0
- data/lib/active_graph/timestamps/updated.rb +9 -0
- data/lib/active_graph/transaction.rb +22 -0
- data/lib/active_graph/transactions.rb +57 -0
- data/lib/active_graph/type_converters.rb +7 -0
- data/lib/active_graph/undeclared_properties.rb +53 -0
- data/lib/active_graph/version.rb +3 -0
- data/lib/active_graph/wrapper.rb +4 -0
- data/lib/rails/generators/active_graph/migration/migration_generator.rb +16 -0
- data/lib/rails/generators/active_graph/migration/templates/migration.erb +9 -0
- data/lib/rails/generators/active_graph/model/model_generator.rb +89 -0
- data/lib/rails/generators/active_graph/model/templates/migration.erb +11 -0
- data/lib/rails/generators/active_graph/model/templates/model.erb +15 -0
- data/lib/rails/generators/active_graph/upgrade_v8/templates/migration.erb +17 -0
- data/lib/rails/generators/active_graph/upgrade_v8/upgrade_v8_generator.rb +34 -0
- data/lib/rails/generators/active_graph_generator.rb +121 -0
- metadata +423 -0
@@ -0,0 +1,57 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ActiveGraph
|
4
|
+
module Transactions
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
included do
|
8
|
+
thread_mattr_accessor :explicit_session, :tx
|
9
|
+
end
|
10
|
+
|
11
|
+
class_methods do
|
12
|
+
def session(**session_config)
|
13
|
+
ActiveGraph::Base.driver.session(**session_config) do |session|
|
14
|
+
self.explicit_session = session
|
15
|
+
yield session
|
16
|
+
session.last_bookmark
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def write_transaction(**config, &block)
|
21
|
+
send_transaction(:write_transaction, **config, &block)
|
22
|
+
end
|
23
|
+
|
24
|
+
def read_transaction(**config, &block)
|
25
|
+
send_transaction(:read_transaction, **config, &block)
|
26
|
+
end
|
27
|
+
|
28
|
+
alias transaction write_transaction
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def send_transaction(method, **config, &block)
|
33
|
+
return yield tx if tx&.open?
|
34
|
+
return run_transaction_work(explicit_session, method, **config, &block) if explicit_session&.open?
|
35
|
+
driver.session do |session|
|
36
|
+
run_transaction_work(session, method, **config, &block)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def run_transaction_work(session, method, **config, &block)
|
41
|
+
implicit = config.delete(:implicit)
|
42
|
+
session.send(method, **config) do |tx|
|
43
|
+
self.tx = tx
|
44
|
+
block.call(tx).tap do |result|
|
45
|
+
if implicit &&
|
46
|
+
[Core::Result, ActiveGraph::Node::Query::QueryProxy, ActiveGraph::Core::Query]
|
47
|
+
.any?(&result.method(:is_a?))
|
48
|
+
result.store
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end.tap { tx.apply_callbacks }
|
52
|
+
rescue ActiveGraph::Rollback
|
53
|
+
# rollbacks are silently swallowed
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
module ActiveGraph
|
2
|
+
module TypeConverters
|
3
|
+
# This exists for legacy purposes. Some gems that the Neo4jrb project does not own
|
4
|
+
# may contain references to this file. We will remove it once that has been dealt with.
|
5
|
+
include ActiveGraph::Shared::TypeConverters
|
6
|
+
end
|
7
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module ActiveGraph
|
2
|
+
# This mixin allows storage and update of undeclared properties in the included class
|
3
|
+
module UndeclaredProperties
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
attr_accessor :undeclared_properties
|
8
|
+
end
|
9
|
+
|
10
|
+
def validate_attributes!(_)
|
11
|
+
end
|
12
|
+
|
13
|
+
def read_attribute(name)
|
14
|
+
respond_to?(name) ? super(name) : read_undeclared_property(name.to_sym)
|
15
|
+
end
|
16
|
+
alias [] read_attribute
|
17
|
+
|
18
|
+
def read_undeclared_property(name)
|
19
|
+
_persisted_obj ? _persisted_obj.properties[name] : (undeclared_properties && undeclared_properties[name])
|
20
|
+
end
|
21
|
+
|
22
|
+
def write_attribute(name, value)
|
23
|
+
if respond_to? "#{name}="
|
24
|
+
super(name, value)
|
25
|
+
else
|
26
|
+
add_undeclared_property(name, value)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
alias []= write_attribute
|
30
|
+
|
31
|
+
def skip_update?
|
32
|
+
super && undeclared_properties.blank?
|
33
|
+
end
|
34
|
+
|
35
|
+
def props_for_create
|
36
|
+
super.merge(undeclared_properties!)
|
37
|
+
end
|
38
|
+
|
39
|
+
def props_for_update
|
40
|
+
super.merge(undeclared_properties!)
|
41
|
+
end
|
42
|
+
|
43
|
+
def undeclared_properties!
|
44
|
+
undeclared_properties || {}
|
45
|
+
ensure
|
46
|
+
self.undeclared_properties = nil
|
47
|
+
end
|
48
|
+
|
49
|
+
def add_undeclared_property(name, value)
|
50
|
+
(self.undeclared_properties ||= {})[name] = value
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'active_graph.rb')
|
4
|
+
|
5
|
+
module ActiveGraph
|
6
|
+
module Generators
|
7
|
+
class MigrationGenerator < ::Rails::Generators::NamedBase
|
8
|
+
include ::ActiveGraph::Generators::SourcePathHelper
|
9
|
+
include ::ActiveGraph::Generators::MigrationHelper
|
10
|
+
|
11
|
+
def create_migration_file
|
12
|
+
migration_template 'migration.erb'
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'active_graph.rb')
|
4
|
+
|
5
|
+
class ActiveGraph::Generators::ModelGenerator < Rails::Generators::NamedBase #:nodoc:
|
6
|
+
include ::ActiveGraph::Generators::SourcePathHelper
|
7
|
+
include ::ActiveGraph::Generators::MigrationHelper
|
8
|
+
|
9
|
+
argument :attributes, type: :array, default: [], banner: 'field:type field:type'
|
10
|
+
|
11
|
+
check_class_collision
|
12
|
+
|
13
|
+
class_option :timestamps, type: :boolean
|
14
|
+
class_option :parent, type: :string, desc: 'The parent class for the generated model'
|
15
|
+
class_option :indices, type: :array, desc: 'The properties which should be indexed'
|
16
|
+
class_option :has_one, type: :array, desc: 'A list of has_one relationships'
|
17
|
+
class_option :has_many, type: :array, desc: 'A list of has_many relationships'
|
18
|
+
|
19
|
+
def create_model_file
|
20
|
+
template 'model.erb', File.join('app/models', class_path, "#{singular_name}.rb")
|
21
|
+
migration_template 'migration.erb', 'create_'
|
22
|
+
end
|
23
|
+
|
24
|
+
protected
|
25
|
+
|
26
|
+
def migration?
|
27
|
+
false
|
28
|
+
end
|
29
|
+
|
30
|
+
def timestamps?
|
31
|
+
options[:timestamps]
|
32
|
+
end
|
33
|
+
|
34
|
+
# rubocop:disable Naming/PredicateName
|
35
|
+
def has_many?
|
36
|
+
options[:has_many]
|
37
|
+
end
|
38
|
+
|
39
|
+
def has_many_statements
|
40
|
+
options[:has_many].each_with_object('') do |key, txt|
|
41
|
+
txt << has_x('has_many', key)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def has_one?
|
46
|
+
options[:has_one]
|
47
|
+
end
|
48
|
+
|
49
|
+
def has_x(method, key)
|
50
|
+
to, from = key.split(':')
|
51
|
+
(from ? "\n #{method}(:#{to}).from(:#{from})\n" : "\n #{method} :#{to}")
|
52
|
+
end
|
53
|
+
|
54
|
+
def has_one_statements
|
55
|
+
txt = ''
|
56
|
+
options[:has_one].each do |key|
|
57
|
+
txt << has_x('has_one', key)
|
58
|
+
end
|
59
|
+
txt
|
60
|
+
end
|
61
|
+
# rubocop:enable Naming/PredicateName
|
62
|
+
|
63
|
+
def indices?
|
64
|
+
options[:indices]
|
65
|
+
end
|
66
|
+
|
67
|
+
def index_fragment(property)
|
68
|
+
return if !options[:indices] || !options[:indices].include?(property)
|
69
|
+
|
70
|
+
"index :#{property}"
|
71
|
+
end
|
72
|
+
|
73
|
+
def parent?
|
74
|
+
options[:parent]
|
75
|
+
end
|
76
|
+
|
77
|
+
def timestamp_statements
|
78
|
+
'
|
79
|
+
property :created_at, type: DateTime
|
80
|
+
# property :created_on, type: Date
|
81
|
+
|
82
|
+
property :updated_at, type: DateTime
|
83
|
+
# property :updated_on, type: Date
|
84
|
+
|
85
|
+
'
|
86
|
+
end
|
87
|
+
|
88
|
+
hook_for :test_framework
|
89
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class <%= class_name %> <%= parent? ? "#{options[:parent].classify}" : "" %>
|
2
|
+
include ActiveGraph::Node
|
3
|
+
<% attributes.reject(&:reference?).each do |attribute| -%>
|
4
|
+
property :<%= attribute.name %><%= ", type: #{attribute.type_class}" unless attribute.type_class == 'any' %><%= "\n " + index_fragment if index_fragment = index_fragment(attribute.name) %>
|
5
|
+
<% end -%>
|
6
|
+
|
7
|
+
<% attributes.select(&:reference?).each do |attribute| -%>
|
8
|
+
has_one :in_or_out_or_both, :<%= attribute.name %>, type: :FILL_IN_RELATIONSHIP_TYPE_HERE
|
9
|
+
<% end -%>
|
10
|
+
|
11
|
+
<%= has_many_statements if has_many? -%>
|
12
|
+
<%= has_one_statements if has_one? -%>
|
13
|
+
|
14
|
+
<%= timestamp_statements if timestamps? -%>
|
15
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class <%= @migration_class_name.underscore.camelize %> < ActiveGraph::Migrations::Base
|
2
|
+
def up
|
3
|
+
<% @schema.each do |type, data|
|
4
|
+
data.each do |element| %>
|
5
|
+
add_<%= type %> <%= element[:label].inspect %>, <%= element[:property_name].inspect %>, force: true
|
6
|
+
<% end
|
7
|
+
end %>
|
8
|
+
end
|
9
|
+
|
10
|
+
def down
|
11
|
+
<% @schema.each do |type, data|
|
12
|
+
data.each do |element| %>
|
13
|
+
drop_<%= type %> <%= element[:label].inspect %>, <%= element[:property_name].inspect %>
|
14
|
+
<% end
|
15
|
+
end %>
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'active_graph.rb')
|
4
|
+
|
5
|
+
module ActiveGraph
|
6
|
+
module Generators
|
7
|
+
class UpgradeV8Generator < ::Rails::Generators::Base
|
8
|
+
include ::ActiveGraph::Generators::SourcePathHelper
|
9
|
+
include ::ActiveGraph::Generators::MigrationHelper
|
10
|
+
|
11
|
+
def create_upgrade_v8_file
|
12
|
+
@schema = load_all_models_schema!
|
13
|
+
migration_template 'migration.erb'
|
14
|
+
end
|
15
|
+
|
16
|
+
def file_name
|
17
|
+
'upgrate_to_v8'
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def load_all_models_schema!
|
23
|
+
Rails.application.eager_load!
|
24
|
+
initialize_all_models!
|
25
|
+
ActiveGraph::ModelSchema.legacy_model_schema_informations
|
26
|
+
end
|
27
|
+
|
28
|
+
def initialize_all_models!
|
29
|
+
models = ActiveGraph::Node.loaded_classes
|
30
|
+
models.map(&:ensure_id_property_info!)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,121 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rails/generators/named_base'
|
4
|
+
require 'rails/generators/active_model'
|
5
|
+
|
6
|
+
module ActiveGraph
|
7
|
+
module Generators #:nodoc:
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
module ActiveGraph::Generators::MigrationHelper
|
12
|
+
extend ActiveSupport::Concern
|
13
|
+
|
14
|
+
def base_migration_file_name(file_name, prefix = '')
|
15
|
+
"#{prefix}#{file_name.parameterize}"
|
16
|
+
end
|
17
|
+
|
18
|
+
def migration_file_name(file_name, prefix = '')
|
19
|
+
"#{Time.now.utc.strftime('%Y%m%d%H%M%S')}_#{base_migration_file_name(file_name, prefix)}.rb"
|
20
|
+
end
|
21
|
+
|
22
|
+
def migration_lookup_at(dirname)
|
23
|
+
Dir.glob("#{dirname}/[0-9]*_*.rb")
|
24
|
+
end
|
25
|
+
|
26
|
+
# Stolen from https://github.com/rails/rails/blob/30767f980faa2d7a0531774ddf040471db74a23b/railties/lib/rails/generators/migration.rb#L20
|
27
|
+
def existing_migration(dirname, file_name)
|
28
|
+
migration_lookup_at(dirname).grep(/\d+_#{file_name}.rb$/).first
|
29
|
+
end
|
30
|
+
|
31
|
+
# :revoke happens when task is invoked with `rails destroy model ModelName`
|
32
|
+
def migration_template(template_name, prefix = '')
|
33
|
+
real_file_name = case @behavior
|
34
|
+
when :revoke
|
35
|
+
existing_migration(
|
36
|
+
'db/neo4j/migrate',
|
37
|
+
base_migration_file_name(file_name, prefix)
|
38
|
+
)
|
39
|
+
else
|
40
|
+
migration_file_name(file_name, prefix)
|
41
|
+
end
|
42
|
+
|
43
|
+
# If running with :revoke and migration doesn't exist, real_file_name = nil
|
44
|
+
return if !real_file_name
|
45
|
+
|
46
|
+
@migration_class_name = file_name.camelize
|
47
|
+
|
48
|
+
# template() method is still run on revoke but it doesn't generate anything
|
49
|
+
# other than a consol message indicating the filepath.
|
50
|
+
# (this appears to be behavior provided by rails)
|
51
|
+
template template_name, File.join('db/neo4j/migrate', real_file_name)
|
52
|
+
|
53
|
+
# On revoke, we need to manually remove the file
|
54
|
+
FileUtils.rm(real_file_name) if @behavior == :revoke
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
module ActiveGraph::Generators::SourcePathHelper
|
59
|
+
extend ActiveSupport::Concern
|
60
|
+
|
61
|
+
module ClassMethods
|
62
|
+
def source_root
|
63
|
+
@_neo4j_source_root ||= File.expand_path(File.join(File.dirname(__FILE__),
|
64
|
+
'active_graph', generator_name, 'templates'))
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
|
70
|
+
class ActiveGraph::Generators::ActiveModel < Rails::Generators::ActiveModel #:nodoc:
|
71
|
+
def self.all(klass)
|
72
|
+
"#{klass}.all"
|
73
|
+
end
|
74
|
+
|
75
|
+
def self.find(klass, params = nil)
|
76
|
+
"#{klass}.find(#{params})"
|
77
|
+
end
|
78
|
+
|
79
|
+
def self.build(klass, params = nil)
|
80
|
+
if params
|
81
|
+
"#{klass}.new(#{params})"
|
82
|
+
else
|
83
|
+
"#{klass}.new"
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def save
|
88
|
+
"#{name}.save"
|
89
|
+
end
|
90
|
+
|
91
|
+
def update_attributes(params = nil)
|
92
|
+
"#{name}.update_attributes(#{params})"
|
93
|
+
end
|
94
|
+
|
95
|
+
def errors
|
96
|
+
"#{name}.errors"
|
97
|
+
end
|
98
|
+
|
99
|
+
def destroy
|
100
|
+
"#{name}.destroy"
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
|
105
|
+
module Rails
|
106
|
+
module Generators
|
107
|
+
class GeneratedAttribute #:nodoc:
|
108
|
+
def type_class
|
109
|
+
case type.to_s.downcase
|
110
|
+
when 'any' then 'any'
|
111
|
+
when 'datetime' then 'DateTime'
|
112
|
+
when 'date' then 'Date'
|
113
|
+
when 'integer', 'number', 'fixnum' then 'Integer'
|
114
|
+
when 'float' then 'Float'
|
115
|
+
else
|
116
|
+
'String'
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|