diff options
author | Reverite <github@reverite.sh> | 2019-03-10 19:19:52 -0700 |
---|---|---|
committer | Reverite <github@reverite.sh> | 2019-03-10 19:19:52 -0700 |
commit | 229e2726cad36066afb210d7087a40cd9f955483 (patch) | |
tree | a14d55e9469f1f339fc40b777827aa4886bb7889 /app/serializers/rest/poll_serializer.rb | |
parent | 715c552fe4c1b2d59bf1f281d77b6e2546bdb531 (diff) | |
parent | 3cef04610cd809c7bd01adc00d34fb3d25261a16 (diff) |
Merge branch 'glitch'
Diffstat (limited to 'app/serializers/rest/poll_serializer.rb')
-rw-r--r-- | app/serializers/rest/poll_serializer.rb | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/app/serializers/rest/poll_serializer.rb b/app/serializers/rest/poll_serializer.rb new file mode 100644 index 000000000..4dae1c09f --- /dev/null +++ b/app/serializers/rest/poll_serializer.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +class REST::PollSerializer < ActiveModel::Serializer + attributes :id, :expires_at, :expired, + :multiple, :votes_count + + has_many :loaded_options, key: :options + + attribute :voted, if: :current_user? + + def id + object.id.to_s + end + + def expired + object.expired? + end + + def voted + object.voted?(current_user.account) + end + + def current_user? + !current_user.nil? + end + + class OptionSerializer < ActiveModel::Serializer + attributes :title, :votes_count + end +end |