Class: Geoff
- Inherits:
-
Object
show all
- Defined in:
- lib/geoff/indexer.rb,
lib/geoff/version.rb,
lib/geoff.rb
Defined Under Namespace
Modules: Indexer
Classes: ContainerLabelMissing, DslSyntaxError, Error, MissingIndexedProperty, MissingNodeDefinition
Constant Summary
collapse
- VERSION =
"0.2.1"
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(*classes_and_builders, &block) ⇒ Geoff
Returns a new instance of Geoff.
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
# File 'lib/geoff.rb', line 64
def initialize *classes_and_builders, &block
options = classes_and_builders.last.is_a?(Hash) ? classes_and_builders.pop : {}
grouped = classes_and_builders.group_by &:class
classes = grouped[Class] || {}
builders = grouped[Geoff] || {}
validate grouped
@container = Container.new
builders.each do |builder|
@container.merge builder.container
end
options.merge!({
parent_node_dsl: nil,
type: nil,
container: @container
})
@children_dsl = ChildrenDsl.new(options, &block) if block_given?
end
|
Instance Attribute Details
#children_dsl ⇒ Object
Returns the value of attribute children_dsl.
62
63
64
|
# File 'lib/geoff.rb', line 62
def children_dsl
@children_dsl
end
|
#container ⇒ Object
Returns the value of attribute container.
62
63
64
|
# File 'lib/geoff.rb', line 62
def container
@container
end
|
Class Method Details
.build_node_map(db) ⇒ Object
40
41
42
43
44
45
46
47
|
# File 'lib/geoff.rb', line 40
def build_node_map db
return {} if db.is_a?(String)
ref_node = db.reference_node
ref_node.rels(:outgoing).inject({}) do |h, r|
h[r.rel_type.to_s] = r.end_node
h
end.merge("ROOT" => ref_node)
end
|
.import(*args) ⇒ Object
30
31
32
33
34
35
36
37
38
|
# File 'lib/geoff.rb', line 30
def import *args
@options = args[1]
Geoff.log @options
db = options.delete(:db) || Neo4j.db.graph
node_map = build_node_map db
Importer.import args[0], db, node_map
Indexer.rebuild_indices(Neo4j.db.graph) unless options[:skip_index]
true
end
|
.log(message) ⇒ Object
49
50
51
|
# File 'lib/geoff.rb', line 49
def log(message)
$stdout.puts message unless silent?
end
|
.options ⇒ Object
57
58
59
|
# File 'lib/geoff.rb', line 57
def options
@options || {}
end
|
.silent? ⇒ Boolean
53
54
55
|
# File 'lib/geoff.rb', line 53
def silent?
options.has_key?(:silent) ? options[:silent] : false
end
|
Instance Method Details
#<=>(other) ⇒ Object
96
97
98
|
# File 'lib/geoff.rb', line 96
def <=> other
to_geoff == other.to_geoff ? 0 : -1
end
|
#inspect ⇒ Object
104
105
106
|
# File 'lib/geoff.rb', line 104
def inspect
"<Geoff: #{to_s}>"
end
|
#to_geoff ⇒ Object
88
89
90
91
92
93
94
|
# File 'lib/geoff.rb', line 88
def to_geoff
return @geoff if @geoff
geoff = "#{add_classes}\n"
geoff += @children_dsl.to_geoff if @children_dsl
@geoff = geoff.chomp
end
|
#to_s ⇒ Object
100
101
102
|
# File 'lib/geoff.rb', line 100
def to_s
to_geoff
end
|