Group methods related to text generation for GraphQL documentation into a module
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
class Comment < ActiveRecord::Base
|
||||
include Flaggable
|
||||
include HasPublicAuthor
|
||||
include Graphqlable
|
||||
|
||||
acts_as_paranoid column: :hidden_at
|
||||
include ActsAsParanoidAliases
|
||||
|
||||
32
app/models/concerns/graphqlable.rb
Normal file
32
app/models/concerns/graphqlable.rb
Normal file
@@ -0,0 +1,32 @@
|
||||
module Graphqlable
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
class_methods do
|
||||
|
||||
def graphql_field_name
|
||||
self.name.gsub('::', '_').underscore.to_sym
|
||||
end
|
||||
|
||||
def graphql_pluralized_field_name
|
||||
self.name.gsub('::', '_').underscore.pluralize.to_sym
|
||||
end
|
||||
|
||||
def graphql_field_description
|
||||
"Find one #{self.model_name.human} by ID"
|
||||
end
|
||||
|
||||
def graphql_pluralized_field_description
|
||||
"Find all #{self.model_name.human.pluralize}"
|
||||
end
|
||||
|
||||
def graphql_type_name
|
||||
self.name.gsub('::', '_')
|
||||
end
|
||||
|
||||
def graphql_type_description
|
||||
"#{self.model_name.human}"
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
@@ -8,6 +8,7 @@ class Debate < ActiveRecord::Base
|
||||
include Searchable
|
||||
include Filterable
|
||||
include HasPublicAuthor
|
||||
include Graphqlable
|
||||
|
||||
acts_as_votable
|
||||
acts_as_paranoid column: :hidden_at
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
class Geozone < ActiveRecord::Base
|
||||
|
||||
include Graphqlable
|
||||
|
||||
has_many :proposals
|
||||
has_many :spending_proposals
|
||||
has_many :debates
|
||||
|
||||
@@ -7,6 +7,7 @@ class Proposal < ActiveRecord::Base
|
||||
include Searchable
|
||||
include Filterable
|
||||
include HasPublicAuthor
|
||||
include Graphqlable
|
||||
|
||||
acts_as_votable
|
||||
acts_as_paranoid column: :hidden_at
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
class ProposalNotification < ActiveRecord::Base
|
||||
|
||||
include Graphqlable
|
||||
|
||||
belongs_to :author, class_name: 'User', foreign_key: 'author_id'
|
||||
belongs_to :proposal
|
||||
|
||||
|
||||
@@ -9,6 +9,8 @@ class User < ActiveRecord::Base
|
||||
acts_as_paranoid column: :hidden_at
|
||||
include ActsAsParanoidAliases
|
||||
|
||||
include Graphqlable
|
||||
|
||||
has_one :administrator
|
||||
has_one :moderator
|
||||
has_one :valuator
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
class Vote < ActsAsVotable::Vote
|
||||
|
||||
include Graphqlable
|
||||
|
||||
def self.public_for_api
|
||||
joins("FULL OUTER JOIN debates ON votable_type = 'Debate' AND votable_id = debates.id").
|
||||
joins("FULL OUTER JOIN proposals ON votable_type = 'Proposal' AND votable_id = proposals.id").
|
||||
|
||||
Reference in New Issue
Block a user