class Alfred::Feedback
Attributes
backend_file[R]
items[RW]
Public Class Methods
CoreServicesIcon(name)
click to toggle source
helper class method for icon
# File lib/alfred/feedback.rb, line 79 def self.CoreServicesIcon(name) { :type => "default" , :name => "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/#{name}.icns" } end
FileIcon(path)
click to toggle source
# File lib/alfred/feedback.rb, line 92 def self.FileIcon(path) { :type => "fileicon" , :name => path , } end
Icon(name)
click to toggle source
# File lib/alfred/feedback.rb, line 86 def self.Icon(name) { :type => "default" , :name => name , } end
new(alfred, opts = {}, &blk)
click to toggle source
# File lib/alfred/feedback.rb, line 12 def initialize(alfred, opts = {}, &blk) @items = [] @core = alfred use_backend(opts) instance_eval(&blk) if block_given? end
Public Instance Methods
add_file_item(path, opts = {})
click to toggle source
# File lib/alfred/feedback.rb, line 25 def add_file_item(path, opts = {}) @items << FileItem.new(path, opts) end
add_item(opts = {})
click to toggle source
# File lib/alfred/feedback.rb, line 20 def add_item(opts = {}) raise ArgumentError, "Feedback item must have title!" if opts[:title].nil? @items << Item.new(opts[:title], opts) end
add_webloc_item(path, opts = {})
click to toggle source
# File lib/alfred/feedback.rb, line 29 def add_webloc_item(path, opts = {}) unless opts[:folder] opts[:folder] = @core.storage_path end @items << WeblocItem.new(path, opts) end
append(from_file)
click to toggle source
# File lib/alfred/feedback.rb, line 139 def append(from_file) @items << File.open(from_file, "rb") { |f| Marshal.load(f) } end
close()
click to toggle source
The workflow is about to complete
-
save cached feedback if necessary
# File lib/alfred/feedback.rb, line 72 def close put_cached_feedback if @backend_file end
dump(to_file)
click to toggle source
# File lib/alfred/feedback.rb, line 131 def dump(to_file) File.open(to_file, "wb") { |f| Marshal.dump(@items, f) } end
encode_with(coder)
click to toggle source
# File lib/alfred/feedback.rb, line 151 def encode_with(coder) coder['items'] = @items end
expired?()
click to toggle source
# File lib/alfred/feedback.rb, line 114 def expired? return false unless @should_expire_after_second Time.now - File.ctime(backend_file) > @should_expire_after_second end
get_cached_feedback()
click to toggle source
# File lib/alfred/feedback.rb, line 119 def get_cached_feedback return nil unless File.exist?(backend_file) return nil if expired? load(@backend_file) self end
load(from_file)
click to toggle source
# File lib/alfred/feedback.rb, line 135 def load(from_file) @items = File.open(from_file, "rb") { |f| Marshal.load(f) } end
marshal_dump()
click to toggle source
Provides marshalling support for use by the Marshal library.
# File lib/alfred/feedback.rb, line 159 def marshal_dump @items end
marshal_load(x)
click to toggle source
Provides marshalling support for use by the Marshal library.
# File lib/alfred/feedback.rb, line 166 def marshal_load(x) @items = x end
merge!(other)
click to toggle source
Merge with other feedback
# File lib/alfred/feedback.rb, line 57 def merge!(other) if other.is_a? Array @items |= other elsif other.is_a? Alfred::Feedback @items |= other.items else raise ArgumentError, "Feedback can not merge with #{other.class}" end end
put_cached_feedback()
click to toggle source
# File lib/alfred/feedback.rb, line 127 def put_cached_feedback dump(backend_file) end
to_xml(with_query = '', items = @items)
click to toggle source
# File lib/alfred/feedback.rb, line 36 def to_xml(with_query = '', items = @items) document = REXML::Element.new("items") @items.sort! if with_query.empty? items.each do |item| document << item.to_xml end else items.each do |item| document << item.to_xml if item.match?(with_query) end end document.to_s end
Also aliased as: to_alfred
to_yaml_properties()
click to toggle source
# File lib/alfred/feedback.rb, line 147 def to_yaml_properties [ '@items' ] end
use_backend(opts = {})
click to toggle source
serialization
# File lib/alfred/feedback.rb, line 104 def use_backend(opts = {}) @backend_file = opts[:file] if opts[:file] @should_expire_after_second = opts[:expire].to_i if opts[:expire] end
Also aliased as: use_cache_file