Class: ProjectStore::Base
- Inherits:
-
Object
- Object
- ProjectStore::Base
- Includes:
- Editing, Entity::Builder
- Defined in:
- lib/project_store/base.rb
Constant Summary
Constants included from Editing
Editing::EDITOR_ENVIRONMENT_VARIABLE
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.
-
#files ⇒ Object
readonly
Returns the value of attribute files.
-
#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.
Attributes included from Editing
Attributes included from Entity::Builder
Instance Method Summary collapse
- #clear ⇒ Object
-
#initialize(path) ⇒ Base
constructor
A new instance of Base.
- #load_entities(&block) ⇒ Object
Methods included from Editing
Methods included from Entity::Builder
#add_decorators, #setup_entity!
Constructor Details
#initialize(path) ⇒ Base
Returns a new instance of Base.
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/project_store/base.rb', line 13 def initialize(path) raise PSE, "Invalid store path '#{path}'!" unless valid_path? path @logger = ProjectStore.logger @path = File. path self.continue_on_error = false @project_entities = {} @files = {} @entity_types = {} self.decorators = {} end |
Instance Attribute Details
#continue_on_error ⇒ Object
Returns the value of attribute continue_on_error.
10 11 12 |
# File 'lib/project_store/base.rb', line 10 def continue_on_error @continue_on_error end |
#entity_types ⇒ Object (readonly)
Returns the value of attribute entity_types.
11 12 13 |
# File 'lib/project_store/base.rb', line 11 def entity_types @entity_types end |
#files ⇒ Object (readonly)
Returns the value of attribute files.
11 12 13 |
# File 'lib/project_store/base.rb', line 11 def files @files end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
11 12 13 |
# File 'lib/project_store/base.rb', line 11 def logger @logger end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
11 12 13 |
# File 'lib/project_store/base.rb', line 11 def path @path end |
#project_entities ⇒ Object (readonly)
Returns the value of attribute project_entities.
11 12 13 |
# File 'lib/project_store/base.rb', line 11 def project_entities @project_entities end |
Instance Method Details
#clear ⇒ Object
24 25 26 27 28 |
# File 'lib/project_store/base.rb', line 24 def clear @project_entities = {} @files = {} @entity_types = {} end |
#load_entities(&block) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/project_store/base.rb', line 30 def load_entities(&block) Dir.glob(File.join(path, '*.yaml')).each do |file| logger.debug "Found store file '#{file}'" begin store = YAML::Store.new(file) files[store] ||= [] store.transaction(true) do store.roots.each do |entity_name| begin logger.debug "Loading '#{entity_name}' entity." entity = store[entity_name] decorate_and_index_entity entity_name, entity, store, &block rescue => e msg = "Invalid entity '#{entity_name}' in file '#{file}' (#{e.message})" dbg_msg = "#{e.message}\nBacktrace:\n#{e.backtrace.join("\n\t")}" if continue_on_error logger.warn msg logger.debug dbg_msg else logger.debug dbg_msg raise PSE, msg end end end end rescue => e logger.error "Invalid store file '#{file}'" logger.debug "#{e.message}\nBacktrace:\n#{e.backtrace.join("\n\t")}" raise unless continue_on_error end end end |