Class: Taggata::Persistent::FileTag

Inherits:
Abstract
  • Object
show all
Defined in:
lib/taggata/persistent/file_tag.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Abstract

bulk_insert, destroy, #destroy, find, find_one, find_or_create, #invalidate_cache, #save, #show

Constructor Details

#initialize(db, file_id, tag_id) ⇒ FileTag

Returns a new instance of FileTag.



7
8
9
10
11
# File 'lib/taggata/persistent/file_tag.rb', line 7

def initialize(db, file_id, tag_id)
  @file_id = file_id
  @tag_id = tag_id
  @db = db
end

Instance Attribute Details

#dbObject (readonly)

Returns the value of attribute db.



5
6
7
# File 'lib/taggata/persistent/file_tag.rb', line 5

def db
  @db
end

#file_idObject (readonly)

Returns the value of attribute file_id.



5
6
7
# File 'lib/taggata/persistent/file_tag.rb', line 5

def file_id
  @file_id
end

#tag_idObject (readonly)

Returns the value of attribute tag_id.



5
6
7
# File 'lib/taggata/persistent/file_tag.rb', line 5

def tag_id
  @tag_id
end

Class Method Details

.new_from_hash(db, hash) ⇒ Object



32
33
34
35
36
# File 'lib/taggata/persistent/file_tag.rb', line 32

def self.new_from_hash(db, hash)
  self.new(db,
           hash[:file_id],
           hash[:tag_id])
end

.tableObject



13
14
15
# File 'lib/taggata/persistent/file_tag.rb', line 13

def self.table
  :taggata_file_tags
end

Instance Method Details

#fileObject



17
18
19
# File 'lib/taggata/persistent/file_tag.rb', line 17

def file
  ::Taggata::Persistent::File.find_one(db, :id => file_id)
end

#tagObject



21
22
23
# File 'lib/taggata/persistent/file_tag.rb', line 21

def tag
  ::Taggata::Persistent::Tag.find_one(db, :id => tag_id)
end

#to_hashObject



25
26
27
28
29
30
# File 'lib/taggata/persistent/file_tag.rb', line 25

def to_hash
  {
    :file_id => file_id,
    :tag_id => tag_id
  }
end