neo4j 2.0.0.alpha.5-java → 2.0.0.alpha.6-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (97) hide show
  1. data/CHANGELOG +12 -0
  2. data/Gemfile +0 -4
  3. data/README.rdoc +106 -62
  4. data/lib/neo4j.rb +7 -33
  5. data/lib/neo4j/performance.rb +43 -0
  6. data/lib/neo4j/rails/accept_id.rb +19 -18
  7. data/lib/neo4j/rails/attributes.rb +366 -120
  8. data/lib/neo4j/rails/finders.rb +41 -15
  9. data/lib/neo4j/rails/has_n.rb +203 -0
  10. data/lib/neo4j/rails/identity.rb +25 -0
  11. data/lib/neo4j/rails/model.rb +65 -242
  12. data/lib/neo4j/rails/nested_attributes.rb +108 -0
  13. data/lib/neo4j/rails/node_persistance.rb +56 -0
  14. data/lib/neo4j/rails/observer.rb +0 -2
  15. data/lib/neo4j/rails/persistence.rb +32 -154
  16. data/lib/neo4j/rails/rack_middleware.rb +26 -2
  17. data/lib/neo4j/rails/rails.rb +9 -6
  18. data/lib/neo4j/rails/railtie.rb +1 -2
  19. data/lib/neo4j/rails/relationship.rb +18 -125
  20. data/lib/neo4j/rails/relationship_persistence.rb +107 -0
  21. data/lib/neo4j/rails/relationships/node_dsl.rb +72 -44
  22. data/lib/neo4j/rails/relationships/relationships.rb +187 -59
  23. data/lib/neo4j/rails/relationships/rels_dsl.rb +18 -17
  24. data/lib/neo4j/rails/relationships/storage.rb +19 -17
  25. data/lib/neo4j/rails/timestamps.rb +53 -51
  26. data/lib/neo4j/rails/transaction.rb +9 -1
  27. data/lib/neo4j/rails/validations/uniqueness.rb +1 -1
  28. data/lib/neo4j/rails/versioning/versioning.rb +2 -2
  29. data/lib/neo4j/version.rb +1 -1
  30. data/lib/orm_adapter/adapters/neo4j.rb +47 -46
  31. data/neo4j.gemspec +1 -1
  32. metadata +10 -69
  33. data/lib/neo4j/algo/algo.rb +0 -294
  34. data/lib/neo4j/batch/batch.rb +0 -4
  35. data/lib/neo4j/batch/indexer.rb +0 -109
  36. data/lib/neo4j/batch/inserter.rb +0 -179
  37. data/lib/neo4j/batch/rule_inserter.rb +0 -24
  38. data/lib/neo4j/batch/rule_node.rb +0 -72
  39. data/lib/neo4j/config.rb +0 -177
  40. data/lib/neo4j/core_ext/class/inheritable_attributes.rb +0 -12
  41. data/lib/neo4j/core_ext/class/rewrite_inheritable_attributes.rb +0 -170
  42. data/lib/neo4j/database.rb +0 -158
  43. data/lib/neo4j/equal.rb +0 -21
  44. data/lib/neo4j/event_handler.rb +0 -263
  45. data/lib/neo4j/has_list/class_methods.rb +0 -11
  46. data/lib/neo4j/has_list/has_list.rb +0 -3
  47. data/lib/neo4j/has_list/mapping.rb +0 -133
  48. data/lib/neo4j/has_n/class_methods.rb +0 -119
  49. data/lib/neo4j/has_n/decl_relationship_dsl.rb +0 -246
  50. data/lib/neo4j/has_n/has_n.rb +0 -3
  51. data/lib/neo4j/has_n/mapping.rb +0 -98
  52. data/lib/neo4j/identity_map.rb +0 -140
  53. data/lib/neo4j/index/class_methods.rb +0 -108
  54. data/lib/neo4j/index/index.rb +0 -39
  55. data/lib/neo4j/index/indexer.rb +0 -341
  56. data/lib/neo4j/index/indexer_registry.rb +0 -68
  57. data/lib/neo4j/index/lucene_query.rb +0 -256
  58. data/lib/neo4j/load.rb +0 -25
  59. data/lib/neo4j/migrations/class_methods.rb +0 -110
  60. data/lib/neo4j/migrations/extensions.rb +0 -58
  61. data/lib/neo4j/migrations/lazy_node_mixin.rb +0 -41
  62. data/lib/neo4j/migrations/migration.rb +0 -112
  63. data/lib/neo4j/migrations/migrations.rb +0 -6
  64. data/lib/neo4j/migrations/node_mixin.rb +0 -80
  65. data/lib/neo4j/migrations/ref_node_wrapper.rb +0 -32
  66. data/lib/neo4j/model.rb +0 -4
  67. data/lib/neo4j/neo4j.rb +0 -216
  68. data/lib/neo4j/node.rb +0 -270
  69. data/lib/neo4j/node_mixin/class_methods.rb +0 -51
  70. data/lib/neo4j/node_mixin/node_mixin.rb +0 -141
  71. data/lib/neo4j/paginated.rb +0 -23
  72. data/lib/neo4j/property/class_methods.rb +0 -79
  73. data/lib/neo4j/property/property.rb +0 -111
  74. data/lib/neo4j/rails/mapping/property.rb +0 -183
  75. data/lib/neo4j/rails/rel_persistence.rb +0 -237
  76. data/lib/neo4j/relationship.rb +0 -239
  77. data/lib/neo4j/relationship_mixin/class_methods.rb +0 -36
  78. data/lib/neo4j/relationship_mixin/relationship_mixin.rb +0 -142
  79. data/lib/neo4j/relationship_set.rb +0 -58
  80. data/lib/neo4j/rels/rels.rb +0 -110
  81. data/lib/neo4j/rels/traverser.rb +0 -102
  82. data/lib/neo4j/rule/class_methods.rb +0 -201
  83. data/lib/neo4j/rule/event_listener.rb +0 -66
  84. data/lib/neo4j/rule/functions/count.rb +0 -43
  85. data/lib/neo4j/rule/functions/function.rb +0 -74
  86. data/lib/neo4j/rule/functions/functions.rb +0 -3
  87. data/lib/neo4j/rule/functions/sum.rb +0 -29
  88. data/lib/neo4j/rule/rule.rb +0 -150
  89. data/lib/neo4j/rule/rule_node.rb +0 -217
  90. data/lib/neo4j/to_java.rb +0 -31
  91. data/lib/neo4j/transaction.rb +0 -73
  92. data/lib/neo4j/traversal/filter_predicate.rb +0 -25
  93. data/lib/neo4j/traversal/prune_evaluator.rb +0 -14
  94. data/lib/neo4j/traversal/rel_expander.rb +0 -31
  95. data/lib/neo4j/traversal/traversal.rb +0 -141
  96. data/lib/neo4j/traversal/traverser.rb +0 -284
  97. data/lib/neo4j/type_converters/type_converters.rb +0 -288
@@ -1,4 +0,0 @@
1
- require 'neo4j/batch/inserter'
2
- require 'neo4j/batch/indexer'
3
- require 'neo4j/batch/rule_inserter'
4
- require 'neo4j/batch/rule_node'
@@ -1,109 +0,0 @@
1
- module Neo4j
2
- module Batch
3
- class Indexer
4
-
5
- delegate :field_types, :entity_type, :indexer_for, :indexed_value_for, :lucene_config, :via_relationships, :to => :@wrapped_indexer
6
-
7
- def initialize(wrapped_indexer)
8
- @wrapped_indexer = wrapped_indexer
9
- @parent_indexers = wrapped_indexer.parent_indexers.collect{|i| Indexer.new(i)}
10
- end
11
-
12
- def indexer_for_field(field, rel_type)
13
- dsl = via_relationships[field]
14
- return nil if dsl.nil?
15
- return nil if dsl.rel_type != rel_type
16
-
17
- target_class = dsl.target_class
18
- self.class.instance_for(target_class)
19
- end
20
-
21
- def index_node_via_rel(rel_type, other, node_props) #:nodoc:
22
- return if node_props.empty? || via_relationships.empty?
23
- props_copy = node_props.clone
24
-
25
- while !props_copy.empty?
26
- indexer = indexer_for_field(props_copy.keys.first, rel_type)
27
-
28
- # put all other fields that are not of this index type in a new hash
29
- other_index = {}
30
- # delete all fields that are not of this index
31
- props_copy.delete_if { |k, v| indexer != indexer_for_field(k, rel_type) && other_index[k] = v }
32
- # add all those properties for this index
33
- indexer && indexer.index_entity(other, props_copy)
34
-
35
- # continue with the remaining fields
36
- props_copy = other_index
37
- end
38
- end
39
-
40
- def index_entity(entity_id, props)
41
- filter_props = props.keys.inject({}) { |memo, field| memo[field] = indexed_value_for(field, props[field]) if field_types.has_key?(field); memo }
42
-
43
- while !filter_props.empty?
44
- # pick one index type
45
- index = batch_index_for_field(filter_props.keys[0])
46
- # put all other fields that are not of this index type in a new hash
47
- other_index = {}
48
- # delete all fields that are not of this index
49
- filter_props.delete_if { |k, v| index != batch_index_for_field(k) && other_index[k] = v }
50
- # add all those properties for this index
51
- index.add(entity_id, filter_props)
52
- # continue with the remaining fields
53
- filter_props = other_index
54
- end
55
-
56
- @parent_indexers.each { |i| i.index_entity(entity_id, props) }
57
- end
58
-
59
- def index_flush
60
- return nil if @batch_indexes.nil?
61
- @batch_indexes.values.each {|index| index.flush}
62
- end
63
-
64
- def index_get(key, value, index_type)
65
- index = @batch_indexes && @batch_indexes[index_type]
66
- return nil if index.nil?
67
- index.get(key,value)
68
- end
69
-
70
- def index_query(query, index_type)
71
- index = @batch_indexes && @batch_indexes[index_type]
72
- return nil if index.nil?
73
- index.query(query)
74
- end
75
-
76
-
77
- def batch_index_for_field(field)
78
- type = field_types[field]
79
- @batch_indexes ||= {}
80
- @batch_indexes[type] ||= create_batch_index_with(type)
81
- end
82
-
83
- def create_batch_index_with(type)
84
- index_config = lucene_config(type)
85
-
86
- if entity_type == :node
87
- self.class.index_provider.node_index(indexer_for.index_names[type], index_config)
88
- else
89
- self.class.index_provider.relationship_index(indexer_for.index_names[type], index_config)
90
- end
91
-
92
- end
93
-
94
- class << self
95
- attr_accessor :index_provider
96
-
97
- def instance_for(clazz)
98
- @instances ||= {}
99
- @instances[clazz.to_s] ||= Indexer.new(clazz._indexer)
100
- end
101
-
102
- # Mostly for testing
103
- def clear_all_instances
104
- @instances = nil
105
- end
106
- end
107
- end
108
- end
109
- end
@@ -1,179 +0,0 @@
1
- module Neo4j
2
- module Batch
3
-
4
- # = Batch Insert
5
- # Neo4j has a batch insert mode that drops support for transactions and concurrency in favor of insertion speed.
6
- # This is useful when you have a big dataset that needs to be loaded once. In our experience, the batch inserter will
7
- # typically inject data around five times faster than running in normal transactional mode.
8
- #
9
- # Be aware that the BatchInserter is intended use is for initial import of data
10
- # * non thread safe
11
- # * non transactional
12
- # * failure to successfully invoke shutdown (properly) results in corrupt database files
13
- #
14
- class Inserter
15
- attr_reader :batch_inserter, :batch_indexer
16
- include ToJava
17
- include Neo4j::Load
18
-
19
- # Creates a new batch inserter.
20
- # Will raise an exception if Neo4j is already running at the same storage_path
21
- #
22
- def initialize(storage_path=Neo4j.config.storage_path, config={})
23
- # check if neo4j is running and using the same storage path
24
- raise "Not allowed to start batch inserter while Neo4j is already running at storage location #{storage_path}" if Neo4j.storage_path == storage_path
25
- @batch_inserter = org.neo4j.kernel.impl.batchinsert.BatchInserterImpl.new(storage_path, config)
26
- Indexer.index_provider = org.neo4j.index.impl.lucene.LuceneBatchInserterIndexProvider.new(@batch_inserter)
27
- @rule_inserter = RuleInserter.new(self)
28
- end
29
-
30
- def running?
31
- @batch_inserter != nil
32
- end
33
-
34
- # This method MUST be called after inserting is completed.
35
- def shutdown
36
- @batch_inserter && @batch_inserter.shutdown
37
- @batch_inserter = nil
38
- @rule_inserter = nil
39
-
40
- Indexer.index_provider
41
- Indexer.index_provider && Indexer.index_provider.shutdown
42
- Indexer.index_provider = nil
43
- Indexer.clear_all_instances
44
- end
45
-
46
- # Creates a node. Returns a Fixnum id of the created node.
47
- # Adds a lucene index if there is a lucene index declared on the properties
48
- def create_node(props=nil, clazz = Neo4j::Node)
49
- props = {} if clazz != Neo4j::Node && props.nil?
50
- props['_classname'] = clazz.to_s if clazz != Neo4j::Node
51
-
52
- props = ensure_valid_props(props)
53
-
54
- node = @batch_inserter.create_node(props)
55
- props && _index(node, props, clazz)
56
- @rule_inserter.node_added(node, props)
57
- node
58
- end
59
-
60
- # returns true if the node exists
61
- def node_exist?(id)
62
- @batch_inserter.node_exists(id)
63
- end
64
-
65
- def ref_node
66
- @batch_inserter.get_reference_node
67
- end
68
-
69
- # creates a relationship between given nodes of given type.
70
- # Returns a fixnum id of the created relationship.
71
- def create_rel(rel_type, from_node, to_node, props=nil, clazz=Neo4j::Relationship)
72
- props = {} if clazz != Neo4j::Relationship && props.nil?
73
- props['_classname'] = clazz.to_s if clazz != Neo4j::Relationship
74
-
75
- props = ensure_valid_props(props)
76
-
77
- rel = @batch_inserter.create_relationship(from_node, to_node, type_to_java(rel_type), props)
78
-
79
- props && _index(rel, props, clazz)
80
-
81
- from_props = node_props(from_node)
82
-
83
- if from_props['_classname']
84
- from_class = to_class(from_props['_classname'])
85
- indexer = Indexer.instance_for(from_class)
86
- indexer.index_node_via_rel(rel_type, to_node, from_props)
87
- end
88
-
89
- to_props = node_props(to_node)
90
- if to_props['_classname']
91
- to_class = to_class(to_props['_classname'])
92
- indexer = Indexer.instance_for(to_class)
93
- indexer.index_node_via_rel(rel_type, from_node, to_props)
94
- end
95
- rel
96
- end
97
-
98
- # Return a hash of all properties of given node
99
- def node_props(node)
100
- @batch_inserter.get_node_properties(node)
101
- end
102
-
103
- # Sets the properties of the given node, overwrites old properties
104
- def set_node_props(node, hash, clazz = Neo4j::Node)
105
- @batch_inserter.set_node_properties(node, hash)
106
- _index(node, hash, clazz)
107
- end
108
-
109
- # Sets the old properties of the given relationship, overwrites old properties
110
- def set_rel_props(rel, hash)
111
- @batch_inserter.set_relationship_properties(rel, hash)
112
- end
113
-
114
- # Returns the properties of the given relationship
115
- def rel_props(rel)
116
- @batch_inserter.get_relationship_properties(rel)
117
- end
118
-
119
- # Returns all the relationships of the given node
120
- def rels(node)
121
- @batch_inserter.getRelationships(node)
122
- end
123
-
124
- # Makes sure additions/updates can be seen by #index_get and #index_query
125
- # so that they are guaranteed to return correct results.
126
- def index_flush(clazz = Neo4j::Node)
127
- indexer = Indexer.instance_for(clazz)
128
- indexer.index_flush
129
- end
130
-
131
- # Returns matches from the index specified by index_type and class.
132
- #
133
- # ==== Parameters
134
- # * key :: the lucene key
135
- # * value :: the lucene value we look for given the key
136
- # * index_type :: :exact or :fulltext
137
- # * clazz :: on which clazz we want to perform the query
138
- #
139
- def index_get(key, value, index_type = :exact, clazz = Neo4j::Node)
140
- indexer = Indexer.instance_for(clazz)
141
- indexer.index_get(key, value, index_type)
142
- end
143
-
144
- # Returns matches from the index specified by index_type and class.
145
- #
146
- # ==== Parameters
147
- # * query :: lucene query
148
- # * index_type :: :exact or :fulltext
149
- # * clazz :: on which clazz we want to perform the query
150
- #
151
- def index_query(query, index_type = :exact, clazz = Neo4j::Node)
152
- indexer = Indexer.instance_for(clazz)
153
- indexer.index_query(query, index_type)
154
- end
155
-
156
- # index the given entity (a node or a relationship)
157
- def _index(entity, props, clazz = Neo4j::Node) #:nodoc:
158
- indexer = Indexer.instance_for(clazz)
159
- indexer.index_entity(entity, props)
160
- end
161
-
162
-
163
- # hmm, maybe faster not wrapping this ?
164
- def to_java_map(hash)
165
- return nil if hash.nil?
166
- map = java.util.HashMap.new
167
- hash.each_pair do |k, v|
168
- case v
169
- when Symbol
170
- map[k.to_s] = v.to_s
171
- else
172
- map[k.to_s] = v
173
- end
174
- end
175
- map
176
- end
177
- end
178
- end
179
- end
@@ -1,24 +0,0 @@
1
- module Neo4j
2
- module Batch
3
- class RuleInserter #:nodoc:
4
- def initialize(inserter)
5
- @inserter = inserter
6
- end
7
-
8
- def node_added(node, props)
9
- classname = props && props['_classname']
10
- classname && create_rules(node, props, classname)
11
- end
12
-
13
-
14
- def create_rules(node, props, classname)
15
- rule_node = RuleNode.rule_node_for(classname, @inserter)
16
- rule_node && rule_node.execute_rules(@inserter, node, props)
17
-
18
- if (clazz = eval("#{classname}.superclass")) && clazz.include?(Neo4j::NodeMixin)
19
- create_rules(node, props, clazz.to_s)
20
- end
21
- end
22
- end
23
- end
24
- end
@@ -1,72 +0,0 @@
1
- module Neo4j
2
- module Batch
3
- class RuleNode #:nodoc:
4
- attr_reader :node
5
- delegate :rules, :to => :@wrapped_rule_node
6
-
7
- def initialize(wrapped_rule_node, node)
8
- @wrapped_rule_node = wrapped_rule_node
9
- @node = node
10
- end
11
-
12
- def execute_rules(inserter, node, props)
13
- rules.each do |rule|
14
- if execute_filter(rule, props)
15
- inserter.create_rel(rule.rule_name, @node, node)
16
- execute_add_functions(inserter, rule, props)
17
- end
18
- end
19
- end
20
-
21
- def execute_add_functions(inserter, rule, props)
22
- rule_props = nil
23
- executed_functions = []
24
- props.keys.each do |key|
25
- functions = rule.functions_for(key)
26
- next unless functions
27
- functions -= executed_functions
28
- rule_props ||= clone_node_props(inserter) #inserter.node_props(@node)
29
- functions.each { |f| executed_functions << f; f.add(rule.rule_name, rule_props, props[key]) }
30
- end
31
- rule_props && inserter.set_node_props(@node, rule_props)
32
- end
33
-
34
- def clone_node_props(inserter)
35
- hash = {}
36
- props = inserter.node_props(@node) # need to clone this since we can't modify it
37
- props.each_pair{|k,v| hash[k]=v}
38
- hash
39
- end
40
-
41
- def execute_filter(rule, props)
42
- if rule.filter.nil?
43
- true
44
- elsif rule.filter.arity != 1
45
- classname = props['_classname'] || 'Neo4j::Node'
46
- clazz = Neo4j::Node.to_class(classname)
47
- wrapper = clazz.load_wrapper(ActiveSupport::HashWithIndifferentAccess.new(props))
48
- wrapper.instance_eval(&rule.filter)
49
- else
50
- rule.filter.call(ActiveSupport::HashWithIndifferentAccess.new(props))
51
- end
52
- end
53
-
54
- class << self
55
- def rule_node_for(classname, inserter)
56
- return nil unless Neo4j::Rule::Rule.has_rules?(classname)
57
- wrapped_rule_node = Neo4j::Rule::Rule.rule_node_for(classname)
58
- @rule_nodes ||= {}
59
- @rule_nodes[classname] ||= RuleNode.new(wrapped_rule_node, create_node(classname, inserter))
60
- end
61
-
62
- def create_node(classname, inserter)
63
- rule_node = inserter.create_node
64
- inserter.create_rel(classname, inserter.ref_node, rule_node)
65
- rule_node
66
- end
67
- end
68
-
69
-
70
- end
71
- end
72
- end
data/lib/neo4j/config.rb DELETED
@@ -1,177 +0,0 @@
1
-
2
- module Neo4j
3
-
4
-
5
- # == Keeps configuration for neo4j
6
- #
7
- # The most important configuration is <tt>Neo4j::Config[:storage_path]</tt> which is used to
8
- # locate where the neo4j database is stored on the filesystem.
9
- # If this directory is empty then a new database will be created, otherwise it will use the
10
- # database from that directory.
11
- #
12
- # ==== Default Configurations
13
- # <tt>:storage_path</tt>:: default <tt>tmp/neo4j</tt> where the database is stored
14
- # <tt>:timestamps</tt>:: default <tt>true</tt> for Rails Neo4j::Model - if timestamps should be used when saving the model
15
- # <tt>:lucene</tt>:: default hash keys: <tt>:fulltext</tt>, <tt>:exact</tt> configuration how the lucene index is stored
16
- # <tt>:enable_rules</tt>:: default true, if false the _all relationship to all instances will not be created and custom rules will not be available.
17
- # <tt>:identity_map</tt>:: default false, See Neo4j::IdentityMap
18
- #
19
- class Config
20
- # This code is copied from merb-core/config.rb.
21
- class << self
22
-
23
- # The location of the default configuration file
24
- def default_file
25
- @default_file ||= File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "config", "neo4j", "config.yml"))
26
- end
27
-
28
- # You can keep all the configuration in your own yaml file
29
- # Also deletes all old configurations.
30
- def default_file=(file_path)
31
- @configuration = nil
32
- @defaults = nil
33
- @default_file = File.expand_path(file_path)
34
- end
35
-
36
- # Returns the hash of default config values for neo4j.
37
- #
38
- # ==== Returns
39
- # Hash:: The defaults for the config.
40
- def defaults
41
- @defaults ||= YAML.load_file(default_file)
42
- end
43
-
44
- # Returns a Java HashMap used by the Java Neo4j API as configuration for the GraphDatabase
45
- def to_java_map
46
- map = java.util.HashMap.new
47
- to_hash.each_pair do |k, v|
48
- case v
49
- when TrueClass
50
- map[k.to_s] = "YES"
51
- when FalseClass
52
- map[k.to_s] = "NO"
53
- when String, Fixnum, Float
54
- map[k.to_s] = v.to_s
55
- # skip list and hash values - not accepted by the Java Neo4j API
56
- end
57
- end
58
- map
59
- end
60
-
61
-
62
- # Returns the expanded path of the Config[:storage_path] property
63
- def storage_path
64
- File.expand_path(self[:storage_path])
65
- end
66
-
67
- # Yields the configuration.
68
- #
69
- # ==== Block parameters
70
- # c :: The configuration parameters, a hash.
71
- #
72
- # ==== Examples
73
- # Neo4j::Config.use do |config|
74
- # config[:storage_path] = '/var/neo4j'
75
- # end
76
- #
77
- # ==== Returns
78
- # nil
79
- def use
80
- @configuration ||= {}
81
- yield @configuration
82
- nil
83
- end
84
-
85
-
86
- # Set the value of a config entry.
87
- #
88
- # ==== Parameters
89
- # key :: The key to set the parameter for.
90
- # val :: The value of the parameter.
91
- #
92
- def []=(key, val)
93
- (@configuration ||= setup)[key] = val
94
- end
95
-
96
-
97
- # Gets the the value of a config entry
98
- #
99
- # ==== Parameters
100
- # key:: The key of the config entry value we want
101
- #
102
- def [](key)
103
- (@configuration ||= setup)[key]
104
- end
105
-
106
-
107
- # Remove the value of a config entry.
108
- #
109
- # ==== Parameters
110
- # key<Object>:: The key of the parameter to delete.
111
- #
112
- # ==== Returns
113
- # The value of the removed entry.
114
- #
115
- def delete(key)
116
- @configuration.delete(key)
117
- end
118
-
119
-
120
- # Remove all configuration. This can be useful for testing purpose.
121
- #
122
- #
123
- # ==== Returns
124
- # nil
125
- #
126
- def delete_all
127
- @configuration = nil
128
- end
129
-
130
-
131
- # Retrieve the value of a config entry, returning the provided default if the key is not present
132
- #
133
- # ==== Parameters
134
- # key:: The key to retrieve the parameter for.
135
- # default::The default value to return if the parameter is not set.
136
- #
137
- # ==== Returns
138
- # The value of the configuration parameter or the default.
139
- #
140
- def fetch(key, default)
141
- @configuration.fetch(key, default)
142
- end
143
-
144
- # Sets up the configuration to use the default.
145
- #
146
- # ==== Returns
147
- # The a new configuration using default values as a hash.
148
- #
149
- def setup()
150
- @configuration = defaults.with_indifferent_access #nested_under_indifferent_access
151
- @configuration.merge!(defaults)
152
- @configuration
153
- end
154
-
155
-
156
- # Returns the configuration as a hash.
157
- #
158
- # ==== Returns
159
- # The config as a hash.
160
- #
161
- def to_hash
162
- @configuration ||= setup
163
- end
164
-
165
- # Returns the config as YAML.
166
- #
167
- # ==== Returns
168
- # The config as YAML.
169
- #
170
- def to_yaml
171
- require "yaml"
172
- @configuration.to_yaml
173
- end
174
- end
175
- end
176
-
177
- end