Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrates to using an enum to indicate what type of status you receive #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

orta
Copy link

@orta orta commented Jan 16, 2019

e.g. emoji or not. This means more status update types can be built from that.

Accepting this would automatically unsubscribe folks from emoji updates, so maybe worth migrating anyone with emoji set up to be status: "_emoji" in their Mongo documents.

Irony that in grabbing the docs for this mongoid enum, I found that you had wrote a ruby enum too. Will comment inline on a few other unrelated changes.

@@ -1,6 +1,6 @@
source 'http://rubygems.org'

ruby '2.5.3'
ruby '~> 2.5.0'
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't want to compile every patch of ruby for every different project, so just moved this to any 2.5.x

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn’t know this worked!

mongoid (7.0.2)
activemodel (>= 5.1, < 6.0.0)
mongoid (5.4.0)
activemodel (~> 4.0)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

interesting, this goes back 2 versions - blocker?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes for sure. Don’t downgrade mongoid. Something’s off.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just revert Gemfile.lock and bundle without a bundle update.

Copy link
Owner

@dblock dblock Jan 16, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like mongoid-enum hasn't been maintained.

I had opened thetron/mongoid-enum#39 a while ago. Emailed the maintainer now. You should probably just use a String field for now.

field :is_bot, type: Boolean, default: false
enum :status, %i[unsubscribed emoji] # , :github]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

enum :status, [:unsubscribed, :emoji] feels like what I'm actually doing IMO, but I'm not gonna fight rubocop

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rubocop -a ; rubocop --auto-gen-config

"ruby.useLanguageServer": true,
"ruby.intellisense": "rubyLocate",
"ruby.codeCompletion": "rcodetools"
}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets vscode jump between all in-app code

….g. emoji or not. To allow extra status update types

belongs_to :team, index: true
validates_presence_of :team

index({ user_id: 1, team_id: 1 }, unique: true)
index(user_name: 1, team_id: 1)

scope :with_emoji, -> { where(emoji: true, :access_token.ne => nil) }
scope :with_emoji, -> { where(status_type: 'emoji', :access_token.ne => nil) }
Copy link
Owner

@dblock dblock Jan 16, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be status: or the field should be status_type no? Needs a test.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also use a symbol or the enum, not a string.

def emoji_count?
!emoji_count.nil? || emoji_count == 0
def not_updating_status?
status == :unsubscribed
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe :off is better than unsubscribe, nbd.

case emoji_count
when 0 then 'No Emoji'
else "#{emoji_count} Emoji"
if using_emoji_status?
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Turn this into

case status
when :off
when :emoji
else 
end

This way you don't need those helpers like using_emoji_status?. Those will proliferate.

@dblock dblock added this to the ongoid milestone Jan 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants