Class: ProjectStore::Base
- Inherits:
-
Object
- Object
- ProjectStore::Base
- Includes:
- Editing
- Defined in:
- lib/project_store/base.rb
Instance Attribute Summary collapse
-
#continue_on_error ⇒ Object
Returns the value of attribute continue_on_error.
-
#entity_types ⇒ Object
readonly
Returns the value of attribute entity_types.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#project_entities ⇒ Object
readonly
Returns the value of attribute project_entities.
-
#stores ⇒ Object
readonly
Returns the value of attribute stores.
Attributes included from Editing
Instance Method Summary collapse
-
#initialize(path) ⇒ Base
constructor
A new instance of Base.
- #load_entities ⇒ Object
Methods included from Editing
Constructor Details
#initialize(path) ⇒ Base
Returns a new instance of Base.
12 13 14 15 16 17 18 19 20 |
# File 'lib/project_store/base.rb', line 12 def initialize(path) raise PSE, "Invalid store path '#{path}'!" unless valid_path? path @logger = ProjectStore.logger @path = File. path @continue_on_error = false @project_entities = {} @stores = {} @entity_types = {} end |
Instance Attribute Details
#continue_on_error ⇒ Object
Returns the value of attribute continue_on_error.
9 10 11 |
# File 'lib/project_store/base.rb', line 9 def continue_on_error @continue_on_error end |
#entity_types ⇒ Object (readonly)
Returns the value of attribute entity_types.
10 11 12 |
# File 'lib/project_store/base.rb', line 10 def entity_types @entity_types end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
10 11 12 |
# File 'lib/project_store/base.rb', line 10 def logger @logger end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
10 11 12 |
# File 'lib/project_store/base.rb', line 10 def path @path end |
#project_entities ⇒ Object (readonly)
Returns the value of attribute project_entities.
10 11 12 |
# File 'lib/project_store/base.rb', line 10 def project_entities @project_entities end |
#stores ⇒ Object (readonly)
Returns the value of attribute stores.
10 11 12 |
# File 'lib/project_store/base.rb', line 10 def stores @stores end |
Instance Method Details
#load_entities ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/project_store/base.rb', line 22 def load_entities Dir.glob(File.join(path, '*.yaml')).each do |file| logger.debug "Found store file '#{file}'" begin store = YAML::Store.new(file) stores[store] ||= [] store.transaction(true) do store.roots.each do |entity_name| begin logger.debug "Loading '#{entity_name}' entity." entity = store[entity_name] add_and_index_entity entity, store, entity_name rescue => e if continue_on_error logger.error "Invalid entity of type '#{entity_name}' in file '#{file}'" logger.debug "#{e.}\nBacktrace:\n#{e.backtrace.join("\n\t")}" else logger.debug "#{e.}\nBacktrace:\n#{e.backtrace.join("\n\t")}" raise PSE, "Invalid entity of type '#{entity_name}' in file '#{file}'" end end end end rescue => e logger.error "Invalid store file '#{file}'" logger.debug "#{e.}\nBacktrace:\n#{e.backtrace.join("\n\t")}" raise unless continue_on_error end end end |