Class: Piggly::Dumper::Index
Overview
The index file stores metadata about every procedure, but the source code is stored in a separate file for each procedure.
Instance Method Summary collapse
-
#[](identifier) ⇒ Object
Returns the Procedure with the given identifier.
-
#initialize(config) ⇒ Index
constructor
A new instance of Index.
-
#label(procedure) ⇒ Object
Returns the shortest human-readable label that distinctly identifies the given procedure from the other procedures in the index.
- #path ⇒ String
-
#procedures ⇒ Object
Returns a list of Procedure values from the index.
-
#update(procedures) ⇒ void
Updates the index with the given list of Procedure values.
Constructor Details
#initialize(config) ⇒ Index
Returns a new instance of Index.
10 11 12 |
# File 'lib/piggly/dumper/index.rb', line 10 def initialize(config) @config = config end |
Instance Method Details
#[](identifier) ⇒ Object
Returns the Procedure with the given identifier
50 51 52 53 |
# File 'lib/piggly/dumper/index.rb', line 50 def [](identifier) p = index[identifier] p.dup if p end |
#label(procedure) ⇒ Object
Returns the shortest human-readable label that distinctly identifies the given procedure from the other procedures in the index
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/piggly/dumper/index.rb', line 57 def label(procedure) others = procedures.reject{|p| p.oid == procedure.oid } same = others.all?{|p| p.name.schema == procedure.name.schema } name = if same procedure.name.name else procedure.name.to_s end samenames = others.select{|p| p.name == procedure.name } if samenames.empty? # Name is unique enough name.to_s else sameargs = samenames.select{|p| p.arg_types == procedure.arg_types } if sameargs.empty? # Name and arg types are unique enough "#{name}(#{procedure.arg_types.join(", ")})" else samemodes = sameargs.select{|p| p.arg_modes == procedure.arg_modes } if samemodes.empty? # Name, arg types, and arg modes are unique enough "#{name}(#{procedure.arg_modes.zip(procedure.arg_types).map{|a,b| "#{a} #{b}" }.join(", ")})" end end end end |
#path ⇒ String
15 16 17 |
# File 'lib/piggly/dumper/index.rb', line 15 def path @config.mkpath("#{@config.cache_root}/Dumper", "index.yml") end |
#procedures ⇒ Object
Returns a list of Procedure values from the index
45 46 47 |
# File 'lib/piggly/dumper/index.rb', line 45 def procedures index.values end |
#update(procedures) ⇒ void
This method returns an undefined value.
Updates the index with the given list of Procedure values
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/piggly/dumper/index.rb', line 21 def update(procedures) newest = Util::Enumerable.index_by(procedures){|x| x.identifier } removed = index.values.reject{|p| newest.include?(p.identifier) } removed.each{|p| p.purge_source(@config) } added = procedures.reject{|p| index.include?(p.identifier) } added.each{|p| p.store_source(@config) } changed = procedures.select do |p| if mine = index[p.identifier] # If both are skeletons, they will have the same source because they # are read from the same file, so don't bother checking that case not (mine.skeleton? and p.skeleton?) and mine.source(@config) != p.source(@config) end end changed.each{|p| p.store_source(@config) } @index = newest store_index end |