Sha256: 0d6ec916baba568504b7dadb38fbe9c6471cbc9a7e08beb7312d776ea51cec3d

Contents?: true

Size: 1.84 KB

Versions: 8

Compression:

Stored size: 1.84 KB

Contents

require File.join(File.dirname(__FILE__), '..', '..', 'neo4j.rb')

class Neo4j::Generators::ModelGenerator < Neo4j::Generators::Base #:nodoc:
	argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
	
	check_class_collision
	
	class_option :timestamps, :type => :boolean
	class_option :parent,     :type => :string, :desc => "The parent class for the generated model"
  class_option :indices,    :type => :array,  :desc => "The properties which should be indexed"
  class_option :has_one,    :type => :array,  :desc => "A list of has_one relationships"
  class_option :has_n,      :type => :array,  :desc => "A list of has_n relationships"

	def create_model_file
		template "model.erb", File.join('app/models', "#{singular_name}.rb")
	end
	
	protected
	def migration?
		false
	end
	
	def timestamps?
		options[:timestamps]
	end

  def has_n?
    options[:has_n]
  end

  def has_n_statements
    txt = ""
    options[:has_n].each do |key|
      to, from = key.split(':')
      txt << (from ? "\n  has_n(:#{to}).from(:#{from})\n" : "\n  has_n :#{to}")
    end
    txt
  end

  def has_one?
    options[:has_one]
  end

  def has_one_statements
    txt = ""
    options[:has_one].each do |key|
      to, from = key.split(':')
      txt << (from ? "\n  has_one(:#{to}).from(:#{from})\n" : "\n  has_one :#{to}")
    end
    txt
  end

  def indices?
    options[:indices]
  end

  def indices_statements
    puts "indices_statements #{options[:indices].inspect}"
    txt = ""
    options[:indices].each do |key|
      txt << %Q{
  index :#{key}}
    end
    txt
  end

	def parent?
		options[:parent]
	end
	
	def timestamp_statements
		%q{
  property :created_at, :type => DateTime
  # property :created_on, :type => Date

  property :updated_at, :type => DateTime
  # property :updated_on, :type => Date
}            
	end
	
	hook_for :test_framework
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
neo4j-2.0.0.alpha.7-java lib/generators/neo4j/model/model_generator.rb
neo4j-2.0.0.alpha.6-java lib/generators/neo4j/model/model_generator.rb
neo4j-2.0.0.alpha.5-java lib/generators/neo4j/model/model_generator.rb
neo4j-2.0.0.alpha.4-java lib/generators/neo4j/model/model_generator.rb
neo4j-2.0.0.alpha.3-java lib/generators/neo4j/model/model_generator.rb
neo4j-1.3.1-java lib/generators/neo4j/model/model_generator.rb
neo4j-1.3.0-java lib/generators/neo4j/model/model_generator.rb
neo4j-1.2.6-java lib/generators/neo4j/model/model_generator.rb