Class: MongoMapper::File
- Inherits:
-
GridFS::GridStore
- Object
- GridFS::GridStore
- MongoMapper::File
- Defined in:
- lib/mm-files/file.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
Class Method Summary collapse
Instance Method Summary collapse
- #[](name) ⇒ Object
-
#initialize(owner, attrs = {}) ⇒ File
constructor
A new instance of File.
Constructor Details
#initialize(owner, attrs = {}) ⇒ File
Returns a new instance of File.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/mm-files/file.rb', line 5 def initialize(owner, attrs = {}) @owner = owner @id = attrs.delete("_id") class_eval do attrs.each do |k,v| define_method(k) do v end end end super(@owner.class.database, attrs["filename"], "r", :root => @owner.collection.name) end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
3 4 5 |
# File 'lib/mm-files/file.rb', line 3 def attributes @attributes end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
3 4 5 |
# File 'lib/mm-files/file.rb', line 3 def id @id end |
Class Method Details
.fetch(owner, filename) ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/mm-files/file.rb', line 24 def self.fetch(owner, filename) db = owner.class.database criteria, = FinderOptions.new(:filename => filename, :metadata => {:_id => owner.id}, :limit => 1).to_a obj = db.collection("#{owner.collection.name}.files").find(criteria, ).next_object if obj self.new(owner, obj) end end |
Instance Method Details
#[](name) ⇒ Object
20 21 22 |
# File 'lib/mm-files/file.rb', line 20 def [](name) @attributes[name.to_s] end |