diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2013-06-03 15:54:34 +0300 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2013-06-03 15:54:34 +0300 |
commit | 144ebcf11fa2a5a3ea8373e4a96723ddf6ec6748 (patch) | |
tree | f2cf2a84c7ef425d847a6b49de3773f9df15cd1e /lib/static_model.rb | |
parent | d2d855d1544cb172111aae375ebdef570b9737a1 (diff) | |
download | gitlab-ci-144ebcf11fa2a5a3ea8373e4a96723ddf6ec6748.tar.gz |
Replace devise with auth via gitlab api
Diffstat (limited to 'lib/static_model.rb')
-rw-r--r-- | lib/static_model.rb | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/lib/static_model.rb b/lib/static_model.rb new file mode 100644 index 0000000..185921d --- /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 |