Class: FabulatorExhibitExtension::TypeCollection

Inherits:
Object
  • Object
show all
Defined in:
lib/fabulator_exhibit_extension/database.rb

Instance Method Summary collapse

Constructor Details

#initialize(db) ⇒ TypeCollection

Returns a new instance of TypeCollection.



111
112
113
# File 'lib/fabulator_exhibit_extension/database.rb', line 111

def initialize(db)
  @db = db
end

Instance Method Details

#[](nom) ⇒ Object



115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/fabulator_exhibit_extension/database.rb', line 115

def [](nom)
  ob = nil
  begin
    ob = @db.fabulator_exhibit_types.find(:first, [ 'name = ?', nom ])
  rescue
    ob = nil
  end
  if ob.nil?
    ob = FabulatorExhibitType.new({
      :name => nom,
      :fabulator_exhibit_id => @db.id
    })
  end
  Type.new(ob)
end

#[]=(nom, hash) ⇒ Object



131
132
133
134
135
136
137
# File 'lib/fabulator_exhibit_extension/database.rb', line 131

def []=(nom, hash)
  ob = self[nom]
  hash.each_pair do |k,v|
    ob[k] = v
  end
  ob.save
end

#to_jsonObject



139
140
141
142
143
144
145
# File 'lib/fabulator_exhibit_extension/database.rb', line 139

def to_json
  '{' +
  @db.fabulator_exhibit_types.find(:all).collect{ |t|
    t.name.to_json + ":" + t.data
  }.join(", ") +
  '}'
end