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 'rspec' | |
| class Flattener | |
| def initialize(array) | |
| raise 'An Array must be passed' unless array.kind_of? Array | |
| @array = array | |
| end | |
| def flatten | |
| do_flatten(@array) |
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 Array | |
| def sequential_search(element) | |
| each do |e| | |
| return e if e == element | |
| end | |
| nil | |
| end | |
| def binary_search(element) |
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 Service | |
| extend ActiveSupport::Concern | |
| included do | |
| def self.call(*args) | |
| new.call(*args) | |
| end | |
| def call | |
| raise '#call method not implemented' |
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 CommentsController < ApplicationController | |
| def create | |
| @post = Post.find(params[:post_id]) | |
| @comment = @post.comments.build(comment_params) | |
| @comment.user_id = current_user.id if current_user | |
| if @comment.save | |
| StatusWorker.perform_aync(@comment.id) | |
| NotifyChannelsWorker.perform_async(@comment.id) | |
| AuthorMailer.notify_mail(@post.author.id).deliver_later |
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 Product < ActiveRecord::Base | |
| has_many :orders | |
| validates :name, presence: true | |
| validates :stock_level, presence: true | |
| validates :min_stock_level, presence: true | |
| before_validation :strip_name | |
| before_save :notify_if_low_on_stock | |
| after_save :notify_product_created |