Class: Fabulator::Exhibit::Actions::Database

Inherits:
Action
  • Object
show all
Defined in:
lib/fabulator/exhibit/actions/item.rb

Instance Method Summary collapse

Instance Method Details

#run(context, autovivify = false) ⇒ Object



53
54
55
56
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
# File 'lib/fabulator/exhibit/actions/item.rb', line 53

def run(context, autovivify = false)
  ret = [ ]
  @context.with(context) do |ctx|
    nom = self.database(ctx).first.to_s
    m = self.mode(ctx).first.to_s
    scopeType = (self.scope_type(ctx).first.to_s rescue nil)
    db = nil
    if m == 'merge' || !scopeType.nil?
    db = Fabulator::Exhibit::Lib.fetch_database(nom)
      if !db.nil? && m == 'overwrite'  # !scope_type.nil? is a consequence
        # remove any items of scope_type
        db[:items].delete_if{ |k,v| v['type'] == scopeType }
      end
    end
    if db.nil?
      db = { :items => {}, :types => {}, :properties => {} }
    end
    Fabulator::Exhibit::Lib.set_database(nom, db)
 
    begin
      ret = self.run_actions(ctx)
    ensure
      Fabulator::Exhibit::Lib.store_database(
        nom,
        Fabulator::Exhibit::Lib.get_database(nom)
      )
    end
  end
  return ret
end