Skip to content
Snippets Groups Projects
Select Git revision
  • ag-test
  • rs-test
  • master default protected
  • test-me-pa
  • mksionek-master-patch-52381
  • new-branch-10
  • test-conflicts
  • test-suggestions
  • alejandro-test
  • patch-25
  • winh-test-image-doscussion
  • stg-lfs-image-test-2
  • stg-lfs-image-test
  • test42016
  • issue_42016
  • issue-32709
  • add-codeowners
  • ClemMakesApps-master-patch-62759
  • bvl-staging-test
  • bvl-merge-base-api
  • v9.2.0-rc6 protected
  • v9.2.0-rc5 protected
  • v9.2.0-rc4 protected
  • v9.2.0-rc3 protected
  • v9.1.4 protected
  • v9.2.0-rc2 protected
  • v9.2.0-rc1 protected
  • v9.1.3 protected
  • v8.17.6 protected
  • v9.0.7 protected
  • v9.1.2 protected
  • v9.1.1 protected
  • v9.2.0.pre protected
  • v9.1.0 protected
  • v9.1.0-rc7 protected
  • v9.1.0-rc6 protected
  • v9.0.6 protected
  • v9.1.0-rc5 protected
  • v9.1.0-rc4 protected
  • v9.1.0-rc3 protected
40 results

snippet.rb

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    snippet.rb 1.53 KiB
    # == Schema Information
    #
    # Table name: snippets
    #
    #  id         :integer          not null, primary key
    #  title      :string(255)
    #  content    :text
    #  author_id  :integer          not null
    #  project_id :integer          not null
    #  created_at :datetime         not null
    #  updated_at :datetime         not null
    #  file_name  :string(255)
    #  expires_at :datetime
    #  type       :string(255)
    #  private    :boolean
    
    class Snippet < ActiveRecord::Base
      include Linguist::BlobHelper
    
      attr_accessible :title, :content, :file_name, :expires_at, :private
    
      belongs_to :author, class_name: "User"
      has_many :notes, as: :noteable, dependent: :destroy
    
      delegate :name, :email, to: :author, prefix: true, allow_nil: true
    
      validates :author, presence: true
      validates :title, presence: true, length: { within: 0..255 }
      validates :file_name, presence: true, length: { within: 0..255 }
      validates :content, presence: true
    
      # Scopes
      scope :fresh, -> { order("created_at DESC") }
      scope :non_expired, -> { where(["expires_at IS NULL OR expires_at > ?", Time.current]) }
      scope :expired, -> { where(["expires_at IS NOT NULL AND expires_at < ?", Time.current]) }
    
      def self.content_types
        [
          ".rb", ".py", ".pl", ".scala", ".c", ".cpp", ".java",
          ".haml", ".html", ".sass", ".scss", ".xml", ".php", ".erb",
          ".js", ".sh", ".coffee", ".yml", ".md"
        ]
      end
    
      def data
        content
      end
    
      def size
        0
      end
    
      def name
        file_name
      end
    
      def mode
        nil
      end
    
      def expired?
        expires_at && expires_at < Time.current
      end
    end