Rails 5.2.2, Neo4J, Docker

Rails 5.2.2, Neo4J, Docker

Пример настройки Rails 5.2.2 и Neo4J в экосистеме Docker/Docker Compose. Указаны файлы необходимы для начала работы в существующем Ruby on Rails проекте. Можно воспринимать как контрольный лист интеграции Rails с Neo4J.

Gemfile

gem 'neo4j', '~> 9.4.0'

config/application.rb (or config/environments/{development|test|production}.rb)

require 'neo4j/railtie'

module App
  class Application < Rails::Application
    config.generators { |g| g.orm :neo4j }
    config.neo4j.session.type = :http
    config.neo4j.session.url = ENV['NEO4J_URL'] || 'http://neo4j:docker@neo:7474'
  end
end

config/neo4j.yml

development:
  type: http
  url: http://neo4j:docker@neo:7474

test:
  type: http
  url: http://neo4j:docker@neo:7575

production:
  type: http
  url: http://neo4j:docker@localhost:7474

docker-compose.yml

version: "3"
services:
  neo:
    image: neo4j:3.5
    ports:
      - 7474:7474
      - 7687:7687
    volumes:
      - ./neo4j/data:/data
      - ./neo4j/logs:/logs

app/models (person.rb)

class Person
  include Neo4j::ActiveNode
  
  # need migrations before use
  property :name
  property :text
  property :score, type: Integer, default: 0

  before_save do
    self.score = score * 100
  end

  self.mapped_label_name = 'Person'
end