Class: Taggata::Persistent::Tag

Inherits:
Abstract
  • Object
show all
Defined in:
lib/taggata/persistent/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, name, id = nil) ⇒ Tag

Returns a new instance of Tag.



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

def initialize(db, name, id = nil)
  @db = db
  @name = name
  @id = id
end

Instance Attribute Details

#dbObject (readonly)

Returns the value of attribute db.



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

def db
  @db
end

#idObject (readonly)

Returns the value of attribute id.



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

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

Class Method Details

.new_from_hash(db, hash) ⇒ Object



28
29
30
31
32
# File 'lib/taggata/persistent/tag.rb', line 28

def self.new_from_hash(db, hash)
  self.new(db,
           hash[:name],
           hash[:id])
end

.tableObject



34
35
36
# File 'lib/taggata/persistent/tag.rb', line 34

def self.table
  :taggata_tags
end

Instance Method Details

#file_tagsObject



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

def file_tags
  FileTag.find(db, :tag_id => id)
end

#filesObject



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

def files
  file_tags.map { |file_tag| file_tag.file }
end

#to_hashObject



21
22
23
24
25
26
# File 'lib/taggata/persistent/tag.rb', line 21

def to_hash
  {
    :name => name,
    :id => id
  }
end