Class: Cynq::Directory
- Inherits:
-
Object
- Object
- Cynq::Directory
- Defined in:
- lib/cynq/directory.rb
Instance Attribute Summary collapse
-
#bucket ⇒ Object
readonly
Returns the value of attribute bucket.
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
-
#keys ⇒ Object
readonly
Returns the value of attribute keys.
Instance Method Summary collapse
- #<<(other_file) ⇒ Object
- #[](key) ⇒ Object
- #content_type_for_key(key) ⇒ Object
- #delete(key) ⇒ Object
- #include?(key) ⇒ Boolean
-
#initialize(bucket_name) ⇒ Directory
constructor
A new instance of Directory.
- #inspect ⇒ Object
- #missing?(key) ⇒ Boolean
- #modified?(other_file) ⇒ Boolean
- #size ⇒ Object
Constructor Details
#initialize(bucket_name) ⇒ Directory
Returns a new instance of Directory.
8 9 10 11 12 |
# File 'lib/cynq/directory.rb', line 8 def initialize(bucket_name) establish_connection find_bucket(bucket_name) read_current_files end |
Instance Attribute Details
#bucket ⇒ Object (readonly)
Returns the value of attribute bucket.
6 7 8 |
# File 'lib/cynq/directory.rb', line 6 def bucket @bucket end |
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
6 7 8 |
# File 'lib/cynq/directory.rb', line 6 def connection @connection end |
#keys ⇒ Object (readonly)
Returns the value of attribute keys.
6 7 8 |
# File 'lib/cynq/directory.rb', line 6 def keys @keys end |
Instance Method Details
#<<(other_file) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/cynq/directory.rb', line 26 def <<(other_file) if file = self[other_file.key] file.body = other_file.body else file = @bucket.files.new({ :key => other_file.key, :body => other_file.body }) ct = content_type_for_key(other_file.key) file.content_type = ct if ct end file.public = true file.save end |
#[](key) ⇒ Object
22 23 24 |
# File 'lib/cynq/directory.rb', line 22 def [](key) @current_files[key] end |
#content_type_for_key(key) ⇒ Object
59 60 61 62 |
# File 'lib/cynq/directory.rb', line 59 def content_type_for_key(key) types = MIME::Types.type_for(File.extname(key)) types.empty? ? nil : types.first.to_s end |
#delete(key) ⇒ Object
41 42 43 44 45 |
# File 'lib/cynq/directory.rb', line 41 def delete(key) if file = self[key] file.destroy end end |
#include?(key) ⇒ Boolean
14 15 16 |
# File 'lib/cynq/directory.rb', line 14 def include?(key) keys.include?(key) end |
#inspect ⇒ Object
51 52 53 |
# File 'lib/cynq/directory.rb', line 51 def inspect "#{self.class.name}: #{@bucket.key} (#{keys.size} files, #{size} bytes)" end |
#missing?(key) ⇒ Boolean
18 19 20 |
# File 'lib/cynq/directory.rb', line 18 def missing?(key) ! include? key end |
#modified?(other_file) ⇒ Boolean
47 48 49 |
# File 'lib/cynq/directory.rb', line 47 def modified?(other_file) other_file.etag != self[other_file.key].etag end |
#size ⇒ Object
55 56 57 |
# File 'lib/cynq/directory.rb', line 55 def size @current_files.values.inject(0) { |sum,file| sum + file.content_length } end |