Module: ActiveGraph::Shared::DeclaredProperty::Index

Included in:
ActiveGraph::Shared::DeclaredProperty
Defined in:
lib/active_graph/shared/declared_property/index.rb

Overview

None of these methods interact with the database. They only keep track of property settings in models. It could (should?) handle the actual indexing/constraining, but that's TBD.

Instance Method Summary collapse

Instance Method Details

#constraint!(type = :unique) ⇒ Object



23
24
25
26
# File 'lib/active_graph/shared/declared_property/index.rb', line 23

def constraint!(type = :unique)
  fail ActiveGraph::InvalidPropertyOptionsError, "Can't set constraint on indexed property #{name} (constraints get indexes automatically)" if index?(:exact)
  options[:constraint] = type
end

#constraint?(type = :unique) ⇒ Boolean

Returns:



14
15
16
# File 'lib/active_graph/shared/declared_property/index.rb', line 14

def constraint?(type = :unique)
  options.key?(:constraint) && options[:constraint] == type
end

#index!(type = :exact) ⇒ Object



18
19
20
21
# File 'lib/active_graph/shared/declared_property/index.rb', line 18

def index!(type = :exact)
  fail ActiveGraph::InvalidPropertyOptionsError, "Can't set index on constrainted property #{name} (constraints get indexes automatically)" if constraint?(:unique)
  options[:index] = type
end

#index?(type = :exact) ⇒ Boolean

Returns:



10
11
12
# File 'lib/active_graph/shared/declared_property/index.rb', line 10

def index?(type = :exact)
  options.key?(:index) && options[:index] == type
end

#index_or_constraint?Boolean

Returns:



6
7
8
# File 'lib/active_graph/shared/declared_property/index.rb', line 6

def index_or_constraint?
  index?(:exact) || constraint?(:unique)
end

#unconstraint!(type = :unique) ⇒ Object



32
33
34
# File 'lib/active_graph/shared/declared_property/index.rb', line 32

def unconstraint!(type = :unique)
  options.delete(:constraint) if constraint?(type)
end

#unindex!(type = :exact) ⇒ Object



28
29
30
# File 'lib/active_graph/shared/declared_property/index.rb', line 28

def unindex!(type = :exact)
  options.delete(:index) if index?(type)
end