Sha256: ff485b13dd83ed32c13b3e2c2b2ed2274011daf73e407cc3bbf66dfedf55489f

Contents?: true

Size: 1.38 KB

Versions: 9

Compression:

Stored size: 1.38 KB

Contents

require 'contextio/api/association_helpers'

class ContextIO
  class Folder
    def self.association_name
      :folder
    end
    ContextIO::API::AssociationHelpers.register_resource(self, :folder)

    # (see ContextIO#api)
    attr_reader :api, :source, :name, :attributes, :delim, :nb_messages,
                :uidvalidity, :nb_unseen_messages
    private :attributes

    # @private
    #
    # For internal use only. Users of this gem shouldn't be calling this
    # directly.
    #
    # @param [API] api A handle on the Context.IO API.
    # @param [Hash{String, Symbol => String, Numeric, Boolean}] options A Hash
    #   of attributes describing the resource.
    def initialize(api, options = {})
      @api = api
      @source = options.delete(:source) || options.delete('source')

      options.each do |key, value|
        instance_variable_set("@#{key}", value)

        unless self.respond_to?(key)
          define_singleton_method(key) do
            instance_variable_get("@#{key}")
          end
        end
      end
    end

    def has_children?
      attributes['HasChildren']
    end

    def marked?
      attributes['Marked']
    end

    def imap_attributes
      attributes
    end

    def messages
      association_class = ContextIO::API::AssociationHelpers.class_for_association_name(:messages)

      @messages ||= association_class.new(api, folder: self)
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
contextio-1.3.0 lib/contextio/folder.rb
contextio-1.2.4 lib/contextio/folder.rb
contextio-1.2.3 lib/contextio/folder.rb
contextio-1.2.2 lib/contextio/folder.rb
contextio-1.2.1 lib/contextio/folder.rb
contextio-1.2.0 lib/contextio/folder.rb
contextio-1.1.0 lib/contextio/folder.rb
contextio-1.0.1 lib/contextio/folder.rb
contextio-1.0.0 lib/contextio/folder.rb