Skip to content

Instantly share code, notes, and snippets.

@leompeters
Last active March 7, 2019 20:18
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leompeters/7ddcf17a9f7cac5212d2 to your computer and use it in GitHub Desktop.
Save leompeters/7ddcf17a9f7cac5212d2 to your computer and use it in GitHub Desktop.
RubyMine Live Templates for commented items at Belanton Team.
You can use these settings on your RubyMine [http://rubymine.org]. Here are some RubyMine Live Templates.
# Commented Active Record module in RDoc
# :category: Data Module
#
# Document the responsibility of the module...
#
# Base Module:: rdoc-ref:Namespace
# Base Class:: Namespace::Class
#
# ===== Related Links
#
# * Namespace::Class
# * Namespace::Class#single_word_instance_method
# * Namespace::Class::single_word_class_method
# * Namespace::Class@Heading1
# * Namespace::Class#single_word_instance_method@Heading1
# * Namespace::Class::single_word_class_method@Heading+With+Multiple+Words
#
# Author:: Leonardo M. Peres <mailto:leonardomarques@belanton.com>
# Copyright:: Copyright (c) %y by %o. All Rights Reserved.
# License:: Licensed under the MIT license [www.opensource.org/licenses/mit-license.php]
#
module $MODULE_NAME$ # :doc:
# :category: Exception Class
#
# Generic Active Record exception class.
#
# Base Module:: rdoc-ref:Namespace
# Base Class:: Namespace::Class
#
# ===== Raises
#
# * <tt>*ArgumentError*</tt> - List of ... +ExceptionErrors+.
#
# ===== Examples
#
# For example due to improper usage of column that +inheritance_column+ points to.
#
# ===== Related Links
#
# * Namespace::Class
# * Namespace::Class#single_word_instance_method
# * Namespace::Class::single_word_class_method
# * Namespace::Class@Heading1
# * Namespace::Class#single_word_instance_method@Heading1
# * Namespace::Class::single_word_class_method@Heading+With+Multiple+Words
#
# Author:: Leonardo M. Peres <mailto:leonardomarques@belanton.com>
# Copyright:: Copyright (c) %y by %o. All Rights Reserved.
# License:: Licensed under the MIT license [www.opensource.org/licenses/mit-license.php]
#
class ActiveRecordError < StandardError # :doc:
end
# :category: Exception Class
#
# Raised when the single-table inheritance mechanism failes to locate the subclass.
#
# Base Module:: rdoc-ref:Namespace
# Base Class:: Namespace::Class
#
# ===== Raises
#
# * <tt>*ArgumentError*</tt> - List of ... +ExceptionErrors+.
#
# ===== Examples
#
# For example due to improper usage of column that +inheritance_column+ points to.
#
# ===== Related Links
#
# * Namespace::Class
# * Namespace::Class#single_word_instance_method
# * Namespace::Class::single_word_class_method
# * Namespace::Class@Heading1
# * Namespace::Class#single_word_instance_method@Heading1
# * Namespace::Class::single_word_class_method@Heading+With+Multiple+Words
#
# Author:: Leonardo M. Peres <mailto:leonardomarques@belanton.com>
# Copyright:: Copyright (c) %y by %o. All Rights Reserved.
# License:: Licensed under the MIT license [www.opensource.org/licenses/mit-license.php]
#
class SubclassNotFound < ActiveRecordError # :doc:
end
$END$
end
# Commented class in RDoc
# :category: Business Class
#
# Document the responsibility of the class...
#
# Base Module:: rdoc-ref:Namespace
# Base Class:: Namespace::Class
#
# ===== Examples
#
# Illustrate the behaviour of the class using examples. Indent examples:
#
# base = Base.new("Example String")
# base.method_name("Example", "more")
#
# ===== Related Links
#
# * Namespace::Class
# * Namespace::Class#single_word_instance_method
# * Namespace::Class::single_word_class_method
# * Namespace::Class@Heading1
# * Namespace::Class#single_word_instance_method@Heading1
# * Namespace::Class::single_word_class_method@Heading+With+Multiple+Words
#
# Author:: Leonardo M. Peres <mailto:leonardomarques@belanton.com>
# Copyright:: Copyright (c) %y by %o. All Rights Reserved.
# License:: Licensed under the MIT license [www.opensource.org/licenses/mit-license.php]
#
class $CLASS_NAME$ # :doc:
# RDOC documents constants as well
MAX_NUMBER_OF_BOOKINGS = 3
# Write comments above for accessors, this will be presented as [R/W]
attr_accessor :first_name
# However this one will be presented as [R].
attr_reader :name
# Read only attributes. Generally used for counter cache.
# attr_readonly :associations_count, ...
# Model associations.
belongs_to :association_name, class_name: 'Namespace::Class', counter_cache: :classes_count
has_many :association_name, -> { order :field_name }, dependent: :destroy,
through: :othoer_association_name, class_name: 'Namespace::Class'
accepts_nested_attributes_for :association_name, allow_destroy: true,
reject_if: lambda { |i| i[:field1_name].blank? && i[:field2_name].blank? }
# Related gems and API's settings.
# has_paper_trail
# Model validations.
# validates :user_id, presence: true
# Model callbacks.
# before_initialize :method_name
# before_save :method_name
# after_initialize :method_name
# after_save :method_name
# Model concerns inclusions.
include ModelConcernable
# Remember the letters in the initial word...
def initialize(attributes = {}) # :notnew: stops RDoc from seeing the initialize method as the new method.
# @name = attributes[:name]
# @email = attributes[:email]
$END$
end
# Private methods if applicable.
private
end
# Commented included class methods concern in RDoc
# :category: Included Module
#
# This module joins all Class methods related to their Related Classes
# (rdoc-ref:Namespace1::Class1 and rdoc-ref:Namespace2::Class2) information.
#
# Base Module:: Namespace::Class::Module
# Base Class:: Namespace::Class
#
# ===== Related Links
#
# * Namespace::Class
# * Namespace::Class#single_word_instance_method
# * Namespace::Class::single_word_class_method
# * Namespace::Class@Heading1
# * Namespace::Class#single_word_instance_method@Heading1
# * Namespace::Class::single_word_class_method@Heading+With+Multiple+Words
#
# Author:: Leonardo M. Peres <mailto:leonardomarques@belanton.com>
# Copyright:: Copyright (c) %y by %o. All Rights Reserved.
# License:: Licensed under the MIT license [www.opensource.org/licenses/mit-license.php]
#
module ClassMethods # :doc:
# Desribe the behaviour of the method...
#
# ===== Arguments
#
# 1. <tt>*param1*</tt> - The id of the object you wish to update a counter on.
# 2. <tt><b>param 2</b></tt> - An Array of Hashes containing the names of the fields to update
# as keys and the amount to update the field by as values.
# 3. <tt>*options*</tt> - Document the third attribute below.
# * +:conditions+ - An SQL fragment like "administrator = 1"
# * +:order+ - An SQL fragment like "created_at DESC, name".
# * +:group+ - An attribute name by which the result should be grouped
# * +:limit+ - An integer determining the limit on the number of rows that should be returned.
# * +:offset+ - An integer determining the offset from where the rows should be fetched.
# * +:joins+ - Either an SQL fragment for additional joins like "LEFT JOIN comments ON comments.post_id = id" (rarely needed)
#
# ===== Returns
#
# * <tt>*param*</tt> - The total number of ... as an +integer+.
#
# ===== Raises
#
# * <tt>*ArgumentError*</tt> - List of ... +ExceptionErrors+.
#
# ===== Examples
#
# # For the Post with id of 5, decrement the comments_count by 1, and
# # increment the actions_count by 1
# Post.update_counters 5, comments_count: -1, actions_count: 1
# # Executes the following SQL:
# # UPDATE posts
# # SET comments_count = comments_count - 1,
# # actions_count = actions_count + 1
# # WHERE id = 5
#
# ===== Related Links
#
# * Namespace::Class
# * Namespace::Class#single_word_instance_method
# * Namespace::Class::single_word_class_method
# * Namespace::Class@Heading1
# * Namespace::Class#single_word_instance_method@Heading1
# * Namespace::Class::single_word_class_method@Heading+With+Multiple+Words
#
# Author:: Leonardo M. Peres <mailto:leonardomarques@belanton.com> on $date_created$ at $time_created$
#
def $METHOD_NAME$ # :doc:
$END$
end
end
# Commented module concern in RDoc
# :category: Concern/Service Module
#
# Document the responsibility of the module...
#
# Base Module:: rdoc-ref:Namespace
# Base Class:: Namespace::Class
#
# ===== Related Links
#
# * Namespace::Class
# * Namespace::Class#single_word_instance_method
# * Namespace::Class::single_word_class_method
# * Namespace::Class@Heading1
# * Namespace::Class#single_word_instance_method@Heading1
# * Namespace::Class::single_word_class_method@Heading+With+Multiple+Words
#
# Author:: Leonardo M. Peres <mailto:leonardomarques@belanton.com>
# Copyright:: Copyright (c) %y by %o. All Rights Reserved.
# License:: Licensed under the MIT license [www.opensource.org/licenses/mit-license.php]
#
module $MODULE_NAME$ # :doc:
extend ActiveSupport::Concern
# :category: Included Scopes
included do # :doc:
# :singleton-method:
# Get Objects with ...
scope :scope_name, -> { where field_name: 1 }
end
# :category: Included Module
#
# This module joins all Class methods related to their Related Classes
# (rdoc-ref:Namespace1::Class1 and rdoc-ref:Namespace2::Class2) information.
#
# Base Module:: Namespace::Class::Module
# Base Class:: Namespace::Class
#
# ===== Related Links
#
# * Namespace::Class
# * Namespace::Class#single_word_instance_method
# * Namespace::Class::single_word_class_method
# * Namespace::Class@Heading1
# * Namespace::Class#single_word_instance_method@Heading1
# * Namespace::Class::single_word_class_method@Heading+With+Multiple+Words
#
# Author:: Leonardo M. Peres <mailto:leonardomarques@belanton.com>
# Copyright:: Copyright (c) %y by %o. All Rights Reserved.
# License:: Licensed under the MIT license [www.opensource.org/licenses/mit-license.php]
#
module ClassMethods # :doc:
$END$
end
# :category: Included Module
#
# This module joins all Instance methods related to their Related Classes
# (rdoc-ref:Namespace1::Class1 and rdoc-ref:Namespace2::Class2) information.
#
# Base Module:: Namespace::Class::Module
# Base Class:: Namespace::Class
#
# ===== Related Links
#
# * Namespace::Class
# * Namespace::Class#single_word_instance_method
# * Namespace::Class::single_word_class_method
# * Namespace::Class@Heading1
# * Namespace::Class#single_word_instance_method@Heading1
# * Namespace::Class::single_word_class_method@Heading+With+Multiple+Words
#
# Author:: Leonardo M. Peres <mailto:leonardomarques@belanton.com>
# Copyright:: Copyright (c) %y by %o. All Rights Reserved.
# License:: Licensed under the MIT license [www.opensource.org/licenses/mit-license.php]
#
module InstanceMethods # :doc:
end
# This method includes instance methods to Namespace::Class::Module module.
#
# ===== Arguments
#
# 1. <tt>*receiver*</tt> - Base class that will use these module's methods.
#
# ===== Related Links
#
# * Namespace::Class::Module::ClassMethods
# * Namespace::Class::Module::InstanceMethods
#
def self.included(receiver)
receiver.extend ClassMethods
receiver.send :include, InstanceMethods
end
end
# Commented method in RDoc
# Describe the behaviour of the method...
#
# ===== Arguments
#
# 1. <tt>*param1*</tt> - The id of the object you wish to update a counter on.
# 2. <tt><b>param 2</b></tt> - An Array of Hashes containing the names of the fields to update
# as keys and the amount to update the field by as values.
# 3. <tt>*options*</tt> - Document the third attribute below.
# * +:conditions+ - An SQL fragment like "administrator = 1"
# * +:order+ - An SQL fragment like "created_at DESC, name".
# * +:group+ - An attribute name by which the result should be grouped
# * +:limit+ - An integer determining the limit on the number of rows that should be returned.
# * +:offset+ - An integer determining the offset from where the rows should be fetched.
# * +:joins+ - Either an SQL fragment for additional joins like "LEFT JOIN comments ON comments.post_id = id" (rarely needed)
#
# ===== Returns
#
# * <tt>*param*</tt> - The total number of ... as an +integer+.
#
# ===== Raises
#
# * <tt>*ArgumentError*</tt> - List of ... +ExceptionErrors+.
#
# ===== Examples
#
# # For the Post with id of 5, decrement the comments_count by 1, and
# # increment the actions_count by 1
# Post.update_counters 5, comments_count: -1, actions_count: 1
# # Executes the following SQL:
# # UPDATE posts
# # SET comments_count = comments_count - 1,
# # actions_count = actions_count + 1
# # WHERE id = 5
#
# ===== Related Links
#
# * Namespace::Class
# * Namespace::Class#single_word_instance_method
# * Namespace::Class::single_word_class_method
# * Namespace::Class@Heading1
# * Namespace::Class#single_word_instance_method@Heading1
# * Namespace::Class::single_word_class_method@Heading+With+Multiple+Words
#
# Author:: Leonardo M. Peres <mailto:leonardomarques@belanton.com> on $date_created$ at $time_created$
#
def $METHOD_NAME$ # :doc:
$END$
end
# Commented included instance methods concern in RDoc
# :category: Included Module
#
# This module joins all Instance methods related to their Related Classes
# (rdoc-ref:Namespace1::Class1 and rdoc-ref:Namespace2::Class2) information.
#
# Base Module:: Namespace::Class::Module
# Base Class:: Namespace::Class
#
# ===== Related Links
#
# * Namespace::Class
# * Namespace::Class#single_word_instance_method
# * Namespace::Class::single_word_class_method
# * Namespace::Class@Heading1
# * Namespace::Class#single_word_instance_method@Heading1
# * Namespace::Class::single_word_class_method@Heading+With+Multiple+Words
#
# Author:: Leonardo M. Peres <mailto:leonardomarques@belanton.com>
# Copyright:: Copyright (c) %y by %o. All Rights Reserved.
# License:: Licensed under the MIT license [www.opensource.org/licenses/mit-license.php]
#
module InstanceMethods # :doc:
# Desribe the behaviour of the method...
#
# ===== Arguments
#
# 1. <tt>*param1*</tt> - The id of the object you wish to update a counter on.
# 2. <tt><b>param 2</b></tt> - An Array of Hashes containing the names of the fields to update
# as keys and the amount to update the field by as values.
# 3. <tt>*options*</tt> - Document the third attribute below.
# * +:conditions+ - An SQL fragment like "administrator = 1"
# * +:order+ - An SQL fragment like "created_at DESC, name".
# * +:group+ - An attribute name by which the result should be grouped
# * +:limit+ - An integer determining the limit on the number of rows that should be returned.
# * +:offset+ - An integer determining the offset from where the rows should be fetched.
# * +:joins+ - Either an SQL fragment for additional joins like "LEFT JOIN comments ON comments.post_id = id" (rarely needed)
#
# ===== Returns
#
# * <tt>*param*</tt> - The total number of ... as an +integer+.
#
# ===== Raises
#
# * <tt>*ArgumentError*</tt> - List of ... +ExceptionErrors+.
#
# ===== Examples
#
# # For the Post with id of 5, decrement the comments_count by 1, and
# # increment the actions_count by 1
# Post.update_counters 5, comments_count: -1, actions_count: 1
# # Executes the following SQL:
# # UPDATE posts
# # SET comments_count = comments_count - 1,
# # actions_count = actions_count + 1
# # WHERE id = 5
#
# ===== Related Links
#
# * Namespace::Class
# * Namespace::Class#single_word_instance_method
# * Namespace::Class::single_word_class_method
# * Namespace::Class@Heading1
# * Namespace::Class#single_word_instance_method@Heading1
# * Namespace::Class::single_word_class_method@Heading+With+Multiple+Words
#
# Author:: Leonardo M. Peres <mailto:leonardomarques@belanton.com> on $date_created$ at $time_created$
#
def $METHOD_NAME$ # :doc:
$END$
end
end
# Commented included scopes for concern in RDoc
# :category: Included Scopes
included do # :doc:
# :singleton-method:
# Get Objects with ...
scope :$METHOD_NAME$, -> { where $END$ }
end
# Commented module in RDoc
# :category: Business Module
#
# Document the responsibility of the module...
#
# Base Module:: rdoc-ref:Namespace
# Base Class:: Namespace::Class
#
# ===== Related Links
#
# * Namespace::Class
# * Namespace::Class#single_word_instance_method
# * Namespace::Class::single_word_class_method
# * Namespace::Class@Heading1
# * Namespace::Class#single_word_instance_method@Heading1
# * Namespace::Class::single_word_class_method@Heading+With+Multiple+Words
#
# Author:: Leonardo M. Peres <mailto:leonardomarques@belanton.com>
# Copyright:: Copyright (c) %y by %o. All Rights Reserved.
# License:: Licensed under the MIT license [www.opensource.org/licenses/mit-license.php]
#
module $MODULE_NAME$ # :doc:
# :category: Exception Class
#
# Generic Namespace exception class.
#
# Base Module:: rdoc-ref:Namespace
# Base Class:: Namespace::Class
#
# ===== Raises
#
# * <tt>*ArgumentError*</tt> - List of ... +ExceptionErrors+.
#
# ===== Examples
#
# For example due to improper usage of column that +inheritance_column+ points to.
#
# ===== Related Links
#
# * Namespace::Class
# * Namespace::Class#single_word_instance_method
# * Namespace::Class::single_word_class_method
# * Namespace::Class@Heading1
# * Namespace::Class#single_word_instance_method@Heading1
# * Namespace::Class::single_word_class_method@Heading+With+Multiple+Words
#
# Author:: Leonardo M. Peres <mailto:leonardomarques@belanton.com>
# Copyright:: Copyright (c) %y by %o. All Rights Reserved.
# License:: Licensed under the MIT license [www.opensource.org/licenses/mit-license.php]
#
class NamespaceError < StandardError # :doc:
end
# :category: Exception Class
#
# Raised when...
#
# Base Module:: rdoc-ref:Namespace
# Base Class:: Namespace::Class
#
# ===== Raises
#
# * <tt>*ArgumentError*</tt> - List of ... +ExceptionErrors+.
#
# ===== Examples
#
# For example due to improper usage of column that +inheritance_column+ points to.
#
# ===== Related Links
#
# * Namespace::Class
# * Namespace::Class#single_word_instance_method
# * Namespace::Class::single_word_class_method
# * Namespace::Class@Heading1
# * Namespace::Class#single_word_instance_method@Heading1
# * Namespace::Class::single_word_class_method@Heading+With+Multiple+Words
#
# Author:: Leonardo M. Peres <mailto:leonardomarques@belanton.com>
# Copyright:: Copyright (c) %y by %o. All Rights Reserved.
# License:: Licensed under the MIT license [www.opensource.org/licenses/mit-license.php]
#
class SpecificError < NamespaceError # :doc:
end
$END$
end
# Comment for rake notes:fixme
#--
# FIXME: Fails if the birthday falls on February 29th. High priority for next deploy.
#++
# Comment for rake notes:optimize
#--
# OPTIMIZE: Refactor this code to make it faster.
#++
# Comment for rake notes:todo
#--
# TODO: Any other way to do this?
#++
#parse("Ruby File Header.rb")
class ${Class_Name} < ActiveRecord::Base
# :category: Concern/Service Module
#
# Document the responsibility of the module...
#
# Base Module:: rdoc-ref:Namespace
# Base Class:: Namespace::Class
#
# ===== Related Links
#
# * Namespace::Class
# * Namespace::Class#single_word_instance_method
# * Namespace::Class::single_word_class_method
# * Namespace::Class@Heading1
# * Namespace::Class#single_word_instance_method@Heading1
# * Namespace::Class::single_word_class_method@Heading+With+Multiple+Words
#
# Author:: Leonardo M. Peres <mailto:leonardomarques@belanton.com>
# Copyright:: Copyright (c) %y by %o. All Rights Reserved.
# License:: Licensed under the MIT license [www.opensource.org/licenses/mit-license.php]
#
module ${Module_Name} # :doc:
extend ActiveSupport::Concern
# :category: Included Scopes
included do # :doc:
# :singleton-method:
# Get Objects with ...
scope :scope_name, -> { where field_name: 1 }
end
# :category: Included Module
#
# This module joins all Class methods related to their Related Classes
# (rdoc-ref:Namespace1::Class1 and rdoc-ref:Namespace2::Class2) information.
#
# Base Module:: Namespace::Class::Module
# Base Class:: Namespace::Class
#
# ===== Related Links
#
# * Namespace::Class
# * Namespace::Class#single_word_instance_method
# * Namespace::Class::single_word_class_method
# * Namespace::Class@Heading1
# * Namespace::Class#single_word_instance_method@Heading1
# * Namespace::Class::single_word_class_method@Heading+With+Multiple+Words
#
# Author:: Leonardo M. Peres <mailto:leonardomarques@belanton.com>
# Copyright:: Copyright (c) %y by %o. All Rights Reserved.
# License:: Licensed under the MIT license [www.opensource.org/licenses/mit-license.php]
#
module ClassMethods # :doc:
end
# :category: Included Module
#
# This module joins all Instance methods related to their Related Classes
# (rdoc-ref:Namespace1::Class1 and rdoc-ref:Namespace2::Class2) information.
#
# Base Module:: Namespace::Class::Module
# Base Class:: Namespace::Class
#
# ===== Related Links
#
# * Namespace::Class
# * Namespace::Class#single_word_instance_method
# * Namespace::Class::single_word_class_method
# * Namespace::Class@Heading1
# * Namespace::Class#single_word_instance_method@Heading1
# * Namespace::Class::single_word_class_method@Heading+With+Multiple+Words
#
# Author:: Leonardo M. Peres <mailto:leonardomarques@belanton.com>
# Copyright:: Copyright (c) %y by %o. All Rights Reserved.
# License:: Licensed under the MIT license [www.opensource.org/licenses/mit-license.php]
#
module InstanceMethods # :doc:
end
# This method includes instance methods to Namespace::Class::Module module.
#
# ===== Arguments
#
# 1. <tt>*receiver*</tt> - Base class that will use these module's methods.
#
# ===== Related Links
#
# * Namespace::Class::Module::ClassMethods
# * Namespace::Class::Module::InstanceMethods
#
def self.included(receiver)
receiver.extend ClassMethods
receiver.send :include, InstanceMethods
end
end
end
-- select specific rows from tables with grouping and ordering
SELECT DISTINCT $alias1$.id, COUNT($alias1$.*) AS $table1$_count, $alias1$.*
FROM $table1$ $alias1$
INNER JOIN $table2$ $alias2$ ON $alias1$.id = $alias2$.$table1$_id
WHERE $alias1$.id = 1
GROUP BY $alias1$.id
HAVING COUNT($alias1$.id) > 2
ORDER BY 1$END$;
-- table1 complete()
-- alias1 complete() "alias1"
-- table2 complete()
-- alias2 complete() "alias2"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment