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
- #meta_equal?(other_file) ⇒ Boolean
- #missing?(key) ⇒ Boolean
- #modified?(other_file) ⇒ Boolean
- #size ⇒ Object
Constructor Details
#initialize(bucket_name) ⇒ Directory
Returns a new instance of Directory.
9 10 11 12 13 |
# File 'lib/cynq/directory.rb', line 9 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.
7 8 9 |
# File 'lib/cynq/directory.rb', line 7 def bucket @bucket end |
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
7 8 9 |
# File 'lib/cynq/directory.rb', line 7 def connection @connection end |
#keys ⇒ Object (readonly)
Returns the value of attribute keys.
7 8 9 |
# File 'lib/cynq/directory.rb', line 7 def keys @keys end |
Instance Method Details
#<<(other_file) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/cynq/directory.rb', line 27 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 }) end ct = content_type_for_key(other_file.key) file.content_type = ct if ct file.public = true file.save end |
#[](key) ⇒ Object
23 24 25 |
# File 'lib/cynq/directory.rb', line 23 def [](key) @current_files[key] end |
#content_type_for_key(key) ⇒ Object
64 65 66 67 |
# File 'lib/cynq/directory.rb', line 64 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
42 43 44 45 46 |
# File 'lib/cynq/directory.rb', line 42 def delete(key) if file = self[key] file.destroy end end |
#include?(key) ⇒ Boolean
15 16 17 |
# File 'lib/cynq/directory.rb', line 15 def include?(key) keys.include?(key) end |
#inspect ⇒ Object
56 57 58 |
# File 'lib/cynq/directory.rb', line 56 def inspect "#{self.class.name}: #{@bucket.key} (#{keys.size} files, #{size} bytes)" end |
#meta_equal?(other_file) ⇒ Boolean
52 53 54 |
# File 'lib/cynq/directory.rb', line 52 def (other_file) self[other_file.key].content_type == other_file.content_type end |
#missing?(key) ⇒ Boolean
19 20 21 |
# File 'lib/cynq/directory.rb', line 19 def missing?(key) ! include? key end |
#modified?(other_file) ⇒ Boolean
48 49 50 |
# File 'lib/cynq/directory.rb', line 48 def modified?(other_file) other_file.etag != self[other_file.key].etag end |
#size ⇒ Object
60 61 62 |
# File 'lib/cynq/directory.rb', line 60 def size @current_files.values.inject(0) { |sum,file| sum + file.content_length } end |