This file contains hidden or 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
| module Translatable | |
| extend ActiveSupport::Concern | |
| included do | |
| extend Macro | |
| extend Migration | |
| include Association | |
| include Attributes | |
| include Dirty | |
| include Queries |
This file contains hidden or 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
| require 'active_support/concern' | |
| module Job | |
| extend ActiveSupport::Concern | |
| included do | |
| %w(before success error after failure).each do |method| | |
| instance_eval %{ | |
| def #{method}(method_name = nil, &block) | |
| _add_callback(:#{method}, :push, method_name, &block) |
This file contains hidden or 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
| class Activity | |
| if ActiveModel::VERSION::STRING =~ /^3/ | |
| extend ActiveModel::Naming | |
| extend ActiveModel::Translation | |
| include ActiveModel::Validations | |
| include ActiveModel::Conversion | |
| include ActiveModel::MassAssignmentSecurity | |
| else | |
| include ActiveModel::Model | |
| end |
This file contains hidden or 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
| # Define what to do when preparing a document or snippet | |
| $.prepare -> | |
| # scope all invocations to `this` (@) | |
| $('.select2', @).select2() | |
| # prepare the whole document | |
| $(document).ready -> | |
| $(document).prepare() | |
| # prepare a snippet of AJAX-loaded content |
This file contains hidden or 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
| # PhantomJS.configure do |config| | |
| # config.executable_path = "#{Rails.root}/lib/phantomjs" | |
| # end | |
| # PhantomJS.run('my_phantom.js') | |
| # PhantomJS.execute | |
| class PhantomJS | |
| include Singleton |
This file contains hidden or 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
| # === EXAMPLE === | |
| # product_type = ProductType.first | |
| # ProductFactory.create_or_update(product_type, properties: { custom_attribute: 'Bla' }) do |p| | |
| # p.property :custom_attribute, 'value' | |
| # p.price :total, 1.55 | |
| # end | |
| class ProductFactory | |
| def initialize(product) | |
| @product = product |
This file contains hidden or 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
| def weeks_count(year) | |
| last_day = Date.new(year).end_of_year | |
| if last_day.cweek == 1 | |
| last_day.prev_week.cweek | |
| else | |
| last_day.cweek | |
| end | |
| end |
This file contains hidden or 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
| module Sanitizable | |
| extend ActiveSupport::Concern | |
| module ClassMethods | |
| # Usage | |
| # sanitizes :content # strips content by default | |
| # sanitizes :content, with: :squish | |
| # sanitizes :content, with: :presence | |
| # Chain multiple sanitizer methods, they are executed in the order they are defined |
This file contains hidden or 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
| module Archivable | |
| extend ActiveSupport::Concern | |
| included do | |
| default_scope -> { where(archived_at: nil) } | |
| scope :archived, -> { where.not(archived_at: nil) } | |
| end | |
| def archived? | |
| !archived_at.nil? |