Created
December 20, 2017 11:03
-
-
Save patrick-gleeson/2932c2b2eb8418e1cee8c25a86d52273 to your computer and use it in GitHub Desktop.
Never do this
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# The coding community is, and should be a welcoming and respectful place, and as such | |
# I don't think it's fair to mock bad code when it's produced by a beginner or student, | |
# or when it's created for free for the public benefit, such as on an open source project. | |
# However, we also need to be accountable to our customers, clients and users, and when | |
# we produce terrible code in exchange for money, we should expect our peers to call us | |
# out on it. | |
# In that spirit, I don't feel guilty about sharing one of the most innovatively | |
# terrible pieces of Ruby code I have ever seen. It was written by a team of professional | |
# developers who were paid handsomely for their time. I will spare their shame by not | |
# mentioning the name of the company, and I have slightly anonymised the code below. | |
# Note the name of the class, the inconsistent snake/camel use, the bizarre naming of fields. | |
# But most of all, please note the absurdity that is `Posts#GetAllPosts(id)`, think about the | |
# bizarre set of circumstances that must have led to the developer deciding that they would | |
# have to roll their own implementation of Mongoid::Document#all... | |
class Posts | |
include Mongoid::Document | |
field :Pos_ID, type: String, default: "" | |
field :Pos_NO, type: String, default: "" | |
field :Tags, type: Array, default: [] | |
field :Pos_text, type: String, default: "" | |
field :Pos_opt, type: Array, default: [] | |
field :opt_score, type: Array, default: [] | |
field :Words, type: Hash, default:{} | |
# field :Pos_Img, type: String | |
mount_uploader :attachment , PostsUploader | |
mount_uploader :pos_attachment , PostsUploader | |
def self.GetAllPosts(id) | |
@mongo=mongo_client.list_databases | |
puts @mongo | |
@data= mongo_client.use("project_DB").database.collections | |
@len=@data.count() | |
if @len>0 | |
for @i in 0..@len-1 | |
if @data[@i].name=="posts" | |
@collection=@data[@i] | |
end | |
end | |
else | |
puts "No collection Found" | |
end | |
@name=@collection | |
# puts @name | |
# @allrecored=@data[1].find().to_a | |
# puts @allrecored | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment