Sha256: 054b4a71a0a410eea6aa1c384b51cc697087b2c7b4e1cd89363b574407383154

Contents?: true

Size: 1.2 KB

Versions: 2

Compression:

Stored size: 1.2 KB

Contents

module StorageRoom
  class Entry < Model
    class_inheritable_accessor :collection
        
    class << self         
      def index_path # :nodoc:
        "#{collection[:@url]}/entries"
      end
            
      def show_path(entry_id) # :nodoc:
        "#{index_path}/#{entry_id}"
      end
            
      def json_name # :nodoc:
        'entry'
      end
      
      def search_path(parameters = {}) # :nodoc:
        parameters.present? ? "#{index_path}?#{parameters.to_query}" : index_path
      end
      
      # Search for objects with specific parameters
      def search(parameters = {})
        Array.load(search_path(parameters))
      end
      
      # Find multiple Entries by their IDs with one query
      def find_by_ids(*ids)
        find_by_urls(*ids.map{|id| show_path(id)})
      end
      
      # Find multiple Entries by their URLs with one query
      def find_by_urls(*urls)
        search(:@url.in => urls)
      end
    end
    
    # The collection of a entry
    def collection
      self.class.collection
    end    
    
    # Has this Entry been trashed?
    def trashed?
      self[:@trash]
    end
    
    def id
      self[:@url] ? self[:@url].split('/').last : nil
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
storage_room-0.3.9 lib/storage_room/models/entry.rb
storage_room-0.3.8 lib/storage_room/models/entry.rb