Group methods related to text generation for GraphQL documentation into a module

This commit is contained in:
Alberto Miedes Garcés
2017-01-26 10:47:12 +01:00
parent e7f55b10e2
commit 83267330a7
10 changed files with 51 additions and 6 deletions

View File

@@ -1,6 +1,7 @@
class Comment < ActiveRecord::Base
include Flaggable
include HasPublicAuthor
include Graphqlable
acts_as_paranoid column: :hidden_at
include ActsAsParanoidAliases

View 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

View File

@@ -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

View File

@@ -1,4 +1,7 @@
class Geozone < ActiveRecord::Base
include Graphqlable
has_many :proposals
has_many :spending_proposals
has_many :debates

View File

@@ -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

View File

@@ -1,4 +1,7 @@
class ProposalNotification < ActiveRecord::Base
include Graphqlable
belongs_to :author, class_name: 'User', foreign_key: 'author_id'
belongs_to :proposal

View File

@@ -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

View File

@@ -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").