summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2013-01-02 23:07:32 -0800
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2013-01-02 23:07:32 -0800
commita1999955eb0b212c818a383bc54f8392194d0bc1 (patch)
treef64f9a9d4c396839b99a263a4c46014db4fa7f4d /lib
parent1b25a8f4374363d546d4a58f47c6fe00c3b3af07 (diff)
parentda03a5c7e25601c2bce8375dbbe1cffc58db7bbf (diff)
downloadgitlab-ce-a1999955eb0b212c818a383bc54f8392194d0bc1.tar.gz
Merge pull request #2461 from gitlabhq/remove_roles
Remove models/roles and return to fat models
Diffstat (limited to 'lib')
-rw-r--r--lib/gitolited.rb11
-rw-r--r--lib/static_model.rb47
2 files changed, 58 insertions, 0 deletions
diff --git a/lib/gitolited.rb b/lib/gitolited.rb
new file mode 100644
index 00000000000..68b9b625525
--- /dev/null
+++ b/lib/gitolited.rb
@@ -0,0 +1,11 @@
+# == Gitolited mixin
+#
+# Provide a shortcut to Gitlab::Gitolite instance by gitolite
+#
+# Used by Project, UsersProject, etc
+#
+module Gitolited
+ def gitolite
+ Gitlab::Gitolite.new
+ end
+end
diff --git a/lib/static_model.rb b/lib/static_model.rb
new file mode 100644
index 00000000000..5b64be1f041
--- /dev/null
+++ b/lib/static_model.rb
@@ -0,0 +1,47 @@
+# 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 new_record?
+ false
+ end
+
+ def persisted?
+ false
+ end
+
+ def destroyed?
+ false
+ end
+
+ def ==(other)
+ if other.is_a? StaticModel
+ id == other.id
+ else
+ super
+ end
+ end
+end