Class: Fsinv::BaseDescription
- Inherits:
-
Object
- Object
- Fsinv::BaseDescription
- Includes:
- Fsinv
- Defined in:
- lib/fsinv/basedescription.rb
Direct Known Subclasses
Constant Summary
Constants included from Fsinv
BYTES_IN_GB, BYTES_IN_GiB, BYTES_IN_KB, BYTES_IN_KiB, BYTES_IN_MB, BYTES_IN_MiB, BYTES_IN_TB, BYTES_IN_TiB, IGNORE_FILES, PSEUDO_FILES, VERSION
Instance Attribute Summary collapse
-
#bytes ⇒ Object
Returns the value of attribute bytes.
-
#ctime ⇒ Object
Returns the value of attribute ctime.
-
#fshugo_tags ⇒ Object
Returns the value of attribute fshugo_tags.
-
#mtime ⇒ Object
Returns the value of attribute mtime.
-
#osx_tags ⇒ Object
Returns the value of attribute osx_tags.
-
#path ⇒ Object
Returns the value of attribute path.
Instance Method Summary collapse
-
#as_json(options = { }) ⇒ Object
to_hash.
- #fshugo_tag_ids(file_path) ⇒ Object
-
#initialize(path, reduced_scan = false) ⇒ BaseDescription
constructor
A new instance of BaseDescription.
- #osx_tag_ids(file_path) ⇒ Object
-
#to_hash ⇒ Object
initialize.
- #to_json(*a) ⇒ Object
Methods included from Fsinv
filestructure_to_db, filestructure_to_xml, inventory_to_json, inventory_to_xml, inventory_to_yaml, parse, pretty_IEC_bytes, pretty_SI_bytes, sanitize_string
Constructor Details
#initialize(path, reduced_scan = false) ⇒ BaseDescription
Returns a new instance of BaseDescription.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/fsinv/basedescription.rb', line 12 def initialize(path, reduced_scan = false) @path = path.encode("UTF-8") @bytes = 0 unless reduced_scan # don't do this if we only want to know file sizes (for pseudofiles, .git folders, etc) @ctime = File.ctime(path) rescue (puts "error getting creation time for file #{path}" if Fsinv.[:verbose]) @mtime = File.ctime(path) rescue (puts "error getting modification time for file #{path}" if Fsinv.[:verbose]) @osx_tags = osx_tag_ids(path) @fshugo_tags = fshugo_tag_ids(path) else @osx_tags = [] @fshugo_tags = [] end end |
Instance Attribute Details
#bytes ⇒ Object
Returns the value of attribute bytes.
10 11 12 |
# File 'lib/fsinv/basedescription.rb', line 10 def bytes @bytes end |
#ctime ⇒ Object
Returns the value of attribute ctime.
10 11 12 |
# File 'lib/fsinv/basedescription.rb', line 10 def ctime @ctime end |
#fshugo_tags ⇒ Object
Returns the value of attribute fshugo_tags.
10 11 12 |
# File 'lib/fsinv/basedescription.rb', line 10 def @fshugo_tags end |
#mtime ⇒ Object
Returns the value of attribute mtime.
10 11 12 |
# File 'lib/fsinv/basedescription.rb', line 10 def mtime @mtime end |
#osx_tags ⇒ Object
Returns the value of attribute osx_tags.
10 11 12 |
# File 'lib/fsinv/basedescription.rb', line 10 def @osx_tags end |
#path ⇒ Object
Returns the value of attribute path.
10 11 12 |
# File 'lib/fsinv/basedescription.rb', line 10 def path @path end |
Instance Method Details
#as_json(options = { }) ⇒ Object
to_hash
41 42 43 |
# File 'lib/fsinv/basedescription.rb', line 41 def as_json( = { }) return to_hash end |
#fshugo_tag_ids(file_path) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/fsinv/basedescription.rb', line 78 def fshugo_tag_ids(file_path) # if we had problem loading (or installing) ffi-xattr # don't do the tags thing at all (fixes FreeBSD bug) return [] unless Fsinv.[:xattr] xattr = Xattr.new(file_path) unless xattr["fshugo"].nil? = xattr["fshugo"].split(";") tag_ids = [] .each do |tag| Fsinv.fshugo_tab.add(tag) unless Fsinv.fshugo_tab.contains?(tag) tag_ids << Fsinv.fshugo_tab.get_id(tag) end return tag_ids #return tags else return [] end end |
#osx_tag_ids(file_path) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/fsinv/basedescription.rb', line 49 def osx_tag_ids(file_path) # well, we can only that if we are on osx, for the # mechanism used is only avalable on that plattform return [] unless /darwin/.match(RUBY_PLATFORM) # == osx # if we had problem loading (or installing) ffi-xattr # don't do the tags thing at all (fixes FreeBSD bug) return [] unless Fsinv.[:xattr] # array with the kMDItemUserTags strings # of the extended file attributes of 'path' = %x{mdls -name 'kMDItemUserTags' -raw "#{file_path}"|tr -d "()\n"}.split(',').map { |tag| tag.strip.gsub(/"(.*?)"/,"\\1") } # if there are now tags, mdls returns "null" -> we don't want this if .length == 1 && [0] == "null" return [] else tag_ids = [] .each do |tag| Fsinv.osx_tab.add(tag) unless Fsinv.osx_tab.contains?(tag) tag_ids << Fsinv.osx_tab.get_id(tag) end return tag_ids end end |
#to_hash ⇒ Object
initialize
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/fsinv/basedescription.rb', line 28 def to_hash p = sanitize_string(@path) rescue "path encoding broken" # there can be ArgumentError and UndefinedConversionError h = { "path" => p, "bytes" => @bytes } h['ctime'] = @ctime unless @ctime.nil? h['mtime'] = @mtime unless @mtime.nil? h["osx_tags"] = @osx_tags unless @osx_tags.empty? h["fshugo_tags"] = @fshugo_tags unless @fshugo_tags.empty? return h end |
#to_json(*a) ⇒ Object
45 46 47 |
# File 'lib/fsinv/basedescription.rb', line 45 def to_json(*a) return as_json.to_json(*a ) end |