Class: ProjectStore::Base

Inherits:
Object
  • Object
show all
Includes:
Editing
Defined in:
lib/project_store/base.rb

Instance Attribute Summary collapse

Attributes included from Editing

#editor

Instance Method Summary collapse

Methods included from Editing

#edit

Constructor Details

#initialize(path) ⇒ Base

Returns a new instance of Base.

Raises:



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.expand_path path
  @continue_on_error = false
  @project_entities = {}
  @stores = {}
  @entity_types = {}
end

Instance Attribute Details

#continue_on_errorObject

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_typesObject (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

#loggerObject (readonly)

Returns the value of attribute logger.



10
11
12
# File 'lib/project_store/base.rb', line 10

def logger
  @logger
end

#pathObject (readonly)

Returns the value of attribute path.



10
11
12
# File 'lib/project_store/base.rb', line 10

def path
  @path
end

#project_entitiesObject (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

#storesObject (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_entitiesObject



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.message}\nBacktrace:\n#{e.backtrace.join("\n\t")}"
            else
              logger.debug "#{e.message}\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.message}\nBacktrace:\n#{e.backtrace.join("\n\t")}"
      raise unless continue_on_error
    end
  end
end