summaryrefslogtreecommitdiff
path: root/app/models
diff options
context:
space:
mode:
authorRobert Speicher <rspeicher@gmail.com>2012-08-10 18:07:50 -0400
committerRobert Speicher <rspeicher@gmail.com>2012-08-10 18:25:15 -0400
commit775418918782d5284000ed0bfea364458c748567 (patch)
treec31e3633a3bcbed17b000f0165cf35edad41f7ca /app/models
parent1413c23c502d5a5cbc9b81f553a245103c1d6e50 (diff)
downloadgitlab-ce-775418918782d5284000ed0bfea364458c748567.tar.gz
Fully embrace Ruby 1.9 hash syntax
Didn't bother with files in db/, config/, or features/
Diffstat (limited to 'app/models')
-rw-r--r--app/models/commit.rb12
-rw-r--r--app/models/event.rb12
-rw-r--r--app/models/issue.rb2
-rw-r--r--app/models/key.rb12
-rw-r--r--app/models/merge_request.rb20
-rw-r--r--app/models/milestone.rb2
-rw-r--r--app/models/note.rb38
-rw-r--r--app/models/project.rb72
-rw-r--r--app/models/snippet.rb20
-rw-r--r--app/models/tree.rb2
-rw-r--r--app/models/user.rb72
-rw-r--r--app/models/users_project.rb10
-rw-r--r--app/models/wiki.rb6
13 files changed, 140 insertions, 140 deletions
diff --git a/app/models/commit.rb b/app/models/commit.rb
index 71c41350c95..5c6b4d88d96 100644
--- a/app/models/commit.rb
+++ b/app/models/commit.rb
@@ -20,7 +20,7 @@ class Commit
:tree,
:id,
:to_patch,
- :to => :commit
+ to: :commit
class << self
@@ -57,7 +57,7 @@ class Commit
def commits_since(repo, date)
commits = repo.heads.map do |h|
- repo.log(h.name, nil, :since => date).each { |c| Commit.new(c, h) }
+ repo.log(h.name, nil, since: date).each { |c| Commit.new(c, h) }
end.flatten.uniq { |c| c.id }
commits.sort! do |x, y|
@@ -69,7 +69,7 @@ class Commit
def commits(repo, ref, path = nil, limit = nil, offset = nil)
if path
- repo.log(ref, path, :max_count => limit, :skip => offset)
+ repo.log(ref, path, max_count: limit, skip: offset)
elsif limit && offset
repo.commits(ref, limit, offset)
else
@@ -86,9 +86,9 @@ class Commit
last = project.commit(from.try(:strip))
result = {
- :commits => [],
- :diffs => [],
- :commit => nil
+ commits: [],
+ diffs: [],
+ commit: nil
}
if first && last
diff --git a/app/models/event.rb b/app/models/event.rb
index c75924e7500..e20b79e2a82 100644
--- a/app/models/event.rb
+++ b/app/models/event.rb
@@ -12,13 +12,13 @@ class Event < ActiveRecord::Base
Merged = 7
belongs_to :project
- belongs_to :target, :polymorphic => true
+ belongs_to :target, polymorphic: true
# For Hash only
serialize :data
scope :recent, order("created_at DESC")
- scope :code_push, where(:action => Pushed)
+ scope :code_push, where(action: Pushed)
def self.determine_action(record)
if [Issue, MergeRequest].include? record.class
@@ -29,7 +29,7 @@ class Event < ActiveRecord::Base
end
def self.recent_for_user user
- where(:project_id => user.projects.map(&:id)).recent
+ where(project_id: user.projects.map(&:id)).recent
end
# Next events currently enabled for system
@@ -106,9 +106,9 @@ class Event < ActiveRecord::Base
end
end
- delegate :name, :email, :to => :author, :prefix => true, :allow_nil => true
- delegate :title, :to => :issue, :prefix => true, :allow_nil => true
- delegate :title, :to => :merge_request, :prefix => true, :allow_nil => true
+ delegate :name, :email, to: :author, prefix: true, allow_nil: true
+ delegate :title, to: :issue, prefix: true, allow_nil: true
+ delegate :title, to: :merge_request, prefix: true, allow_nil: true
end
# == Schema Information
#
diff --git a/app/models/issue.rb b/app/models/issue.rb
index d8ca59c23db..454b13586ac 100644
--- a/app/models/issue.rb
+++ b/app/models/issue.rb
@@ -7,7 +7,7 @@ class Issue < ActiveRecord::Base
belongs_to :milestone
validates :description,
- :length => { :within => 0..2000 }
+ length: { within: 0..2000 }
acts_as_list
diff --git a/app/models/key.rb b/app/models/key.rb
index 6b90b315d82..cfcb1f63c26 100644
--- a/app/models/key.rb
+++ b/app/models/key.rb
@@ -6,16 +6,16 @@ class Key < ActiveRecord::Base
belongs_to :project
validates :title,
- :presence => true,
- :length => { :within => 0..255 }
+ presence: true,
+ length: { within: 0..255 }
validates :key,
- :presence => true,
- :length => { :within => 0..5000 }
+ presence: true,
+ length: { within: 0..5000 }
before_save :set_identifier
before_validation :strip_white_space
- delegate :name, :email, :to => :user, :prefix => true
+ delegate :name, :email, to: :user, prefix: true
validate :unique_key
def strip_white_space
@@ -23,7 +23,7 @@ class Key < ActiveRecord::Base
end
def unique_key
- query = Key.where(:key => key)
+ query = Key.where(key: key)
query = query.where('(project_id IS NULL OR project_id = ?)', project_id) if project_id
if (query.count > 0)
errors.add :key, 'already exist.'
diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb
index a77081c9528..47966d669f6 100644
--- a/app/models/merge_request.rb
+++ b/app/models/merge_request.rb
@@ -20,7 +20,7 @@ class MergeRequest < ActiveRecord::Base
validate :validate_branches
def self.find_all_by_branch(branch_name)
- where("source_branch like :branch or target_branch like :branch", :branch => branch_name)
+ where("source_branch like :branch or target_branch like :branch", branch: branch_name)
end
def human_state
@@ -48,7 +48,7 @@ class MergeRequest < ActiveRecord::Base
end
def mark_as_unchecked
- self.update_attributes(:state => UNCHECKED)
+ self.update_attributes(state: UNCHECKED)
end
def can_be_merged?
@@ -101,11 +101,11 @@ class MergeRequest < ActiveRecord::Base
end
def merge_event
- self.project.events.where(:target_id => self.id, :target_type => "MergeRequest", :action => Event::Merged).last
+ self.project.events.where(target_id: self.id, target_type: "MergeRequest", action: Event::Merged).last
end
def closed_event
- self.project.events.where(:target_id => self.id, :target_type => "MergeRequest", :action => Event::Closed).last
+ self.project.events.where(target_id: self.id, target_type: "MergeRequest", action: Event::Closed).last
end
def commits
@@ -128,7 +128,7 @@ class MergeRequest < ActiveRecord::Base
end
def mark_as_unmergable
- self.update_attributes :state => CANNOT_BE_MERGED
+ self.update_attributes state: CANNOT_BE_MERGED
end
def reloaded_commits
@@ -150,11 +150,11 @@ class MergeRequest < ActiveRecord::Base
def merge!(user_id)
self.mark_as_merged!
Event.create(
- :project => self.project,
- :action => Event::Merged,
- :target_id => self.id,
- :target_type => "MergeRequest",
- :author_id => user_id
+ project: self.project,
+ action: Event::Merged,
+ target_id: self.id,
+ target_type: "MergeRequest",
+ author_id: user_id
)
end
diff --git a/app/models/milestone.rb b/app/models/milestone.rb
index 7fdfe29edc8..592c57f948c 100644
--- a/app/models/milestone.rb
+++ b/app/models/milestone.rb
@@ -24,7 +24,7 @@ class Milestone < ActiveRecord::Base
end
def participants
- User.where(:id => issues.map(&:assignee_id))
+ User.where(id: issues.map(&:assignee_id))
end
def percent_complete
diff --git a/app/models/note.rb b/app/models/note.rb
index 8a26cd05b44..711a4ee6935 100644
--- a/app/models/note.rb
+++ b/app/models/note.rb
@@ -3,18 +3,18 @@ require 'file_size_validator'
class Note < ActiveRecord::Base
belongs_to :project
- belongs_to :noteable, :polymorphic => true
+ belongs_to :noteable, polymorphic: true
belongs_to :author,
- :class_name => "User"
+ class_name: "User"
delegate :name,
- :to => :project,
- :prefix => true
+ to: :project,
+ prefix: true
delegate :name,
:email,
- :to => :author,
- :prefix => true
+ to: :author,
+ prefix: true
attr_protected :author, :author_id
attr_accessor :notify
@@ -23,19 +23,19 @@ class Note < ActiveRecord::Base
validates_presence_of :project
validates :note,
- :presence => true,
- :length => { :within => 0..5000 }
+ presence: true,
+ length: { within: 0..5000 }
validates :attachment,
- :file_size => {
- :maximum => 10.megabytes.to_i
+ file_size: {
+ maximum: 10.megabytes.to_i
}
- scope :common, where(:noteable_id => nil)
+ scope :common, where(noteable_id: nil)
- scope :today, where("created_at >= :date", :date => Date.today)
- scope :last_week, where("created_at >= :date", :date => (Date.today - 7.days))
- scope :since, lambda { |day| where("created_at >= :date", :date => (day)) }
+ scope :today, where("created_at >= :date", date: Date.today)
+ scope :last_week, where("created_at >= :date", date: (Date.today - 7.days))
+ scope :since, lambda { |day| where("created_at >= :date", date: (day)) }
scope :fresh, order("created_at DESC")
scope :inc_author_project, includes(:project, :author)
scope :inc_author, includes(:author)
@@ -43,11 +43,11 @@ class Note < ActiveRecord::Base
mount_uploader :attachment, AttachmentUploader
def self.create_status_change_note(noteable, author, status)
- create({ :noteable => noteable,
- :project => noteable.project,
- :author => author,
- :note => "_Status changed to #{status}_" },
- :without_protection => true)
+ create({ noteable: noteable,
+ project: noteable.project,
+ author: author,
+ note: "_Status changed to #{status}_" },
+ without_protection: true)
end
def notify
diff --git a/app/models/project.rb b/app/models/project.rb
index 3ab44bdffd6..de1911f13b9 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -9,19 +9,19 @@ class Project < ActiveRecord::Base
#
# Relations
#
- belongs_to :owner, :class_name => "User"
- has_many :users, :through => :users_projects
- has_many :events, :dependent => :destroy
- has_many :merge_requests, :dependent => :destroy
- has_many :issues, :dependent => :destroy, :order => "closed, created_at DESC"
- has_many :milestones, :dependent => :destroy
- has_many :users_projects, :dependent => :destroy
- has_many :notes, :dependent => :destroy
- has_many :snippets, :dependent => :destroy
- has_many :deploy_keys, :dependent => :destroy, :foreign_key => "project_id", :class_name => "Key"
- has_many :hooks, :dependent => :destroy, :class_name => "ProjectHook"
- has_many :wikis, :dependent => :destroy
- has_many :protected_branches, :dependent => :destroy
+ belongs_to :owner, class_name: "User"
+ has_many :users, through: :users_projects
+ has_many :events, dependent: :destroy
+ has_many :merge_requests, dependent: :destroy
+ has_many :issues, dependent: :destroy, order: "closed, created_at DESC"
+ has_many :milestones, dependent: :destroy
+ has_many :users_projects, dependent: :destroy
+ has_many :notes, dependent: :destroy
+ has_many :snippets, dependent: :destroy
+ has_many :deploy_keys, dependent: :destroy, foreign_key: "project_id", class_name: "Key"
+ has_many :hooks, dependent: :destroy, class_name: "ProjectHook"
+ has_many :wikis, dependent: :destroy
+ has_many :protected_branches, dependent: :destroy
attr_accessor :error_code
@@ -33,15 +33,15 @@ class Project < ActiveRecord::Base
#
# Scopes
#
- scope :public_only, where(:private_flag => false)
- scope :without_user, lambda { |user| where("id not in (:ids)", :ids => user.projects.map(&:id) ) }
+ scope :public_only, where(private_flag: false)
+ scope :without_user, lambda { |user| where("id not in (:ids)", ids: user.projects.map(&:id) ) }
def self.active
joins(:issues, :notes, :merge_requests).order("issues.created_at, notes.created_at, merge_requests.created_at DESC")
end
def self.search query
- where("name like :query or code like :query or path like :query", :query => "%#{query}%")
+ where("name like :query or code like :query or path like :query", query: "%#{query}%")
end
def self.create_by_user(params, user)
@@ -53,7 +53,7 @@ class Project < ActiveRecord::Base
project.save!
# Add user as project master
- project.users_projects.create!(:project_access => UsersProject::MASTER, :user => user)
+ project.users_projects.create!(project_access: UsersProject::MASTER, user: user)
# when project saved no team member exist so
# project repository should be updated after first user add
@@ -82,28 +82,28 @@ class Project < ActiveRecord::Base
# Validations
#
validates :name,
- :uniqueness => true,
- :presence => true,
- :length => { :within => 0..255 }
+ uniqueness: true,
+ presence: true,
+ length: { within: 0..255 }
validates :path,
- :uniqueness => true,
- :presence => true,
- :format => { :with => /^[a-zA-Z][a-zA-Z0-9_\-\.]*$/,
- :message => "only letters, digits & '_' '-' '.' allowed. Letter should be first" },
- :length => { :within => 0..255 }
+ uniqueness: true,
+ presence: true,
+ format: { with: /^[a-zA-Z][a-zA-Z0-9_\-\.]*$/,
+ message: "only letters, digits & '_' '-' '.' allowed. Letter should be first" },
+ length: { within: 0..255 }
validates :description,
- :length => { :within => 0..2000 }
+ length: { within: 0..2000 }
validates :code,
- :presence => true,
- :uniqueness => true,
- :format => { :with => /^[a-zA-Z][a-zA-Z0-9_\-\.]*$/,
- :message => "only letters, digits & '_' '-' '.' allowed. Letter should be first" },
- :length => { :within => 1..255 }
+ presence: true,
+ uniqueness: true,
+ format: { with: /^[a-zA-Z][a-zA-Z0-9_\-\.]*$/,
+ message: "only letters, digits & '_' '-' '.' allowed. Letter should be first" },
+ length: { within: 1..255 }
- validates :owner, :presence => true
+ validates :owner, presence: true
validate :check_limit
validate :repo_name
@@ -134,19 +134,19 @@ class Project < ActiveRecord::Base
end
def common_notes
- notes.where(:noteable_type => ["", nil]).inc_author_project
+ notes.where(noteable_type: ["", nil]).inc_author_project
end
def build_commit_note(commit)
- notes.new(:noteable_id => commit.id, :noteable_type => "Commit")
+ notes.new(noteable_id: commit.id, noteable_type: "Commit")
end
def commit_notes(commit)
- notes.where(:noteable_id => commit.id, :noteable_type => "Commit", :line_code => nil)
+ notes.where(noteable_id: commit.id, noteable_type: "Commit", line_code: nil)
end
def commit_line_notes(commit)
- notes.where(:noteable_id => commit.id, :noteable_type => "Commit").where("line_code is not null")
+ notes.where(noteable_id: commit.id, noteable_type: "Commit").where("line_code is not null")
end
def public?
diff --git a/app/models/snippet.rb b/app/models/snippet.rb
index e5f04bb228b..2c941499f1f 100644
--- a/app/models/snippet.rb
+++ b/app/models/snippet.rb
@@ -2,29 +2,29 @@ class Snippet < ActiveRecord::Base
include Linguist::BlobHelper
belongs_to :project
- belongs_to :author, :class_name => "User"
- has_many :notes, :as => :noteable, :dependent => :destroy
+ belongs_to :author, class_name: "User"
+ has_many :notes, as: :noteable, dependent: :destroy
delegate :name,
:email,
- :to => :author,
- :prefix => true
+ to: :author,
+ prefix: true
attr_protected :author, :author_id, :project, :project_id
validates_presence_of :project_id
validates_presence_of :author_id
validates :title,
- :presence => true,
- :length => { :within => 0..255 }
+ presence: true,
+ length: { within: 0..255 }
validates :file_name,
- :presence => true,
- :length => { :within => 0..255 }
+ presence: true,
+ length: { within: 0..255 }
validates :content,
- :presence => true,
- :length => { :within => 0..10000 }
+ presence: true,
+ length: { within: 0..10000 }
scope :fresh, order("created_at DESC")
scope :non_expired, where(["expires_at IS NULL OR expires_at > ?", Time.current])
diff --git a/app/models/tree.rb b/app/models/tree.rb
index 9d60f83015f..bc95d335520 100644
--- a/app/models/tree.rb
+++ b/app/models/tree.rb
@@ -11,7 +11,7 @@ class Tree
:size,
:text?,
:colorize,
- :to => :tree
+ to: :tree
def initialize(raw_tree, project, ref = nil, path = nil)
@project, @ref, @path = project, ref, path,
diff --git a/app/models/user.rb b/app/models/user.rb
index ff27660a6ee..92c81c83d41 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -11,58 +11,58 @@ class User < ActiveRecord::Base
attr_accessor :force_random_password
- has_many :users_projects, :dependent => :destroy
- has_many :projects, :through => :users_projects
- has_many :my_own_projects, :class_name => "Project", :foreign_key => :owner_id
- has_many :keys, :dependent => :destroy
+ has_many :users_projects, dependent: :destroy
+ has_many :projects, through: :users_projects
+ has_many :my_own_projects, class_name: "Project", foreign_key: :owner_id
+ has_many :keys, dependent: :destroy
has_many :events,
- :class_name => "Event",
- :foreign_key => :author_id,
- :dependent => :destroy
+ class_name: "Event",
+ foreign_key: :author_id,
+ dependent: :destroy
has_many :recent_events,
- :class_name => "Event",
- :foreign_key => :author_id,
- :order => "id DESC"
+ class_name: "Event",
+ foreign_key: :author_id,
+ order: "id DESC"
has_many :issues,
- :foreign_key => :author_id,
- :dependent => :destroy
+ foreign_key: :author_id,
+ dependent: :destroy
has_many :notes,
- :foreign_key => :author_id,
- :dependent => :destroy
+ foreign_key: :author_id,
+ dependent: :destroy
has_many :assigned_issues,
- :class_name => "Issue",
- :foreign_key => :assignee_id,
- :dependent => :destroy
+ class_name: "Issue",
+ foreign_key: :assignee_id,
+ dependent: :destroy
has_many :merge_requests,
- :foreign_key => :author_id,
- :dependent => :destroy
+ foreign_key: :author_id,
+ dependent: :destroy
has_many :assigned_merge_requests,
- :class_name => "MergeRequest",
- :foreign_key => :assignee_id,
- :dependent => :destroy
+ class_name: "MergeRequest",
+ foreign_key: :assignee_id,
+ dependent: :destroy
validates :projects_limit,
- :presence => true,
- :numericality => {:greater_than_or_equal_to => 0}
+ presence: true,
+ numericality: {greater_than_or_equal_to: 0}
- validates :bio, :length => { :within => 0..255 }
+ validates :bio, length: { within: 0..255 }
before_save :ensure_authentication_token
alias_attribute :private_token, :authentication_token
- scope :not_in_project, lambda { |project| where("id not in (:ids)", :ids => project.users.map(&:id) ) }
- scope :admins, where(:admin => true)
- scope :blocked, where(:blocked => true)
- scope :active, where(:blocked => false)
+ scope :not_in_project, lambda { |project| where("id not in (:ids)", ids: project.users.map(&:id) ) }
+ scope :admins, where(admin: true)
+ scope :blocked, where(blocked: true)
+ scope :active, where(blocked: false)
- before_validation :generate_password, :on => :create
+ before_validation :generate_password, on: :create
def generate_password
if self.force_random_password
@@ -94,17 +94,17 @@ class User < ActiveRecord::Base
else
password = Devise.friendly_token[0, 8].downcase
@user = User.create(
- :name => name,
- :email => email,
- :password => password,
- :password_confirmation => password,
- :projects_limit => Gitlab.config.default_projects_limit
+ name: name,
+ email: email,
+ password: password,
+ password_confirmation: password,
+ projects_limit: Gitlab.config.default_projects_limit
)
end
end
def self.search query
- where("name like :query or email like :query", :query => "%#{query}%")
+ where("name like :query or email like :query", query: "%#{query}%")
end
end
# == Schema Information
diff --git a/app/models/users_project.rb b/app/models/users_project.rb
index 4ff86290a92..36e6d9045b6 100644
--- a/app/models/users_project.rb
+++ b/app/models/users_project.rb
@@ -12,18 +12,18 @@ class UsersProject < ActiveRecord::Base
after_save :update_repository
after_destroy :update_repository
- validates_uniqueness_of :user_id, :scope => [:project_id]
+ validates_uniqueness_of :user_id, scope: [:project_id]
validates_presence_of :user_id
validates_presence_of :project_id
- delegate :name, :email, :to => :user, :prefix => true
+ delegate :name, :email, to: :user, prefix: true
def self.bulk_import(project, user_ids, project_access)
UsersProject.transaction do
user_ids.each do |user_id|
users_project = UsersProject.new(
- :project_access => project_access,
- :user_id => user_id
+ project_access: project_access,
+ user_id: user_id
)
users_project.project = project
users_project.save
@@ -35,7 +35,7 @@ class UsersProject < ActiveRecord::Base
UsersProject.transaction do
project_ids.each do |project_id|
users_project = UsersProject.new(
- :project_access => project_access,
+ project_access: project_access,
)
users_project.project_id = project_id
users_project.user_id = user.id
diff --git a/app/models/wiki.rb b/app/models/wiki.rb
index d9ec069d14b..3c4952cd291 100644
--- a/app/models/wiki.rb
+++ b/app/models/wiki.rb
@@ -1,10 +1,10 @@
class Wiki < ActiveRecord::Base
belongs_to :project
belongs_to :user
- has_many :notes, :as => :noteable, :dependent => :destroy
+ has_many :notes, as: :noteable, dependent: :destroy
- validates :content, :title, :user_id, :presence => true
- validates :title, :length => 1..250
+ validates :content, :title, :user_id, presence: true
+ validates :title, length: 1..250
before_update :set_slug