Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/app/roles
diff options
context:
space:
mode:
authorRobert Speicher <rspeicher@gmail.com>2012-09-02 07:39:28 +0400
committerRobert Speicher <rspeicher@gmail.com>2012-09-02 21:40:07 +0400
commit8db2a59d0b6959a78ea7be4663dd9a858dff9f98 (patch)
treef93ac13153e00c20cf66331827f7fa19b4fb1a00 /app/roles
parent877aa5458627d42d03a7f204d02db9d326af006c (diff)
Add StaticModel role, and add it to Commit model
Instead of doing this: link_to(commit.id, project_commit_path(project, id: commit.id)) Note.create(noteable_id: commit.id, noteable_type: "Commit", ...) It lets us do this: link_to(commit.id, project_commit_path(project, commit)) Note.create(noteable: commit, ...)
Diffstat (limited to 'app/roles')
-rw-r--r--app/roles/static_model.rb35
1 files changed, 35 insertions, 0 deletions
diff --git a/app/roles/static_model.rb b/app/roles/static_model.rb
new file mode 100644
index 00000000000..d26c8f47501
--- /dev/null
+++ b/app/roles/static_model.rb
@@ -0,0 +1,35 @@
+# Provides an ActiveRecord-like interface to a model whose data is not persisted to a database.
+module StaticModel
+ extend ActiveSupport::Concern
+
+ module ClassMethods
+ # Used by ActiveRecord's polymorphic association to set object_id
+ def primary_key
+ 'id'
+ end
+
+ # Used by ActiveRecord's polymorphic association to set object_type
+ def base_class
+ self
+ end
+ end
+
+ # Used by AR for fetching attributes
+ #
+ # Pass it along if we respond to it.
+ def [](key)
+ send(key) if respond_to?(key)
+ end
+
+ def to_param
+ id
+ end
+
+ def persisted?
+ false
+ end
+
+ def destroyed?
+ false
+ end
+end