This file contains 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
# In controller | |
result = TaxCalculator.new(order).call | |
if result[:success] | |
render json: { value: result[:value] } | |
else | |
render json: { errors: result[:errors] }, status: 422 | |
end | |
# The service | |
class TaxCalculator |
This file contains 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
Wf.new | |
.chain { CloseProject.new(project) } | |
.chain { NotifyProjectClosed(project) } | |
.chain { Log.new(:project_closed, project) } | |
.chain { render json: project } | |
.on_dam { |error_pool| render json: {errors: error_pool}, status: 422 } | |
This file contains 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 accept_group_terms | |
if current_entity.user? && notification.group_terms? | |
if params[:terms_of_service][:checked] | |
user_group = notification.entity.user_groups.with_user(current_entity).first | |
if user_group | |
user_group.terms_accepted_at = Time.now | |
user_group.save | |
notification.mark_as_read_by(current_entity).save! | |
render_notif | |
else |
This file contains 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 FormObjectBase | |
include ::ActiveModel::Validations | |
attr_reader :object, :params | |
def initialize(object) | |
@object = object | |
end | |
def assign(params) |
This file contains 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 Author::Work < AR::Base | |
scope :with_text, -> { where.not(text: nil) } | |
scope :started, -> { where(status: 0) } | |
scope :in_progress, -> { started.with_text } | |
end |
This file contains 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 trace_calls_on | |
scope = {} | |
trace = TracePoint.new(:call, :line) do |tp| | |
case tp.event | |
when :call then puts "#{tp.path}:#{tp.lineno} #{tp.defined_class}::#{tp.method_id} " \ | |
"called from #{scope[:path]}:#{scope[:lineno]} #{scope[:class]}::#{scope[:method_id]}" | |
when :line then scope = { | |
event: :line, | |
lineno: tp.lineno, | |
path: tp.path, |
This file contains 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 RefineryPatch | |
def self.included(base) | |
base.send :helper_method, | |
:current_refinery_user, | |
:refinery_user_signed_in?, | |
:refinery_user? if base.respond_to? :helper_method | |
end | |
def current_refinery_user |
This file contains 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 'yaml' | |
CAP = YAML.load_file("./config/deploy.yml") | |
require "bundler/capistrano" | |
set :bundle_cmd, "/usr/local/rvm/gems/ree-1.8.7-2011.03/bin/bundle" | |
set :bundle_without, [:development, :test] | |
default_run_options[:pty] = true # Must be set for the password prompt from git to work | |
set :repository, CAP["repository"] # Your clone URL |
This file contains 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 UsersController < ApplicationController | |
respond_to :html, :json | |
def index | |
@json = User.all.to_gmaps4rails | |
respond_with @json | |
end | |
end |
This file contains 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
-------------------------------------------------------------------------------------------- | |
With one object saved, another in memory | |
-------------------------------------------------------------------------------------------- | |
#setup | |
subject.copywriter_languages.create Factory.attributes_for(:copywriter_language, status: "deleted") | |
subject.copywriter_languages.build Factory.attributes_for(:copywriter_language, status: "pending") | |
#Round 1 | |
#checking default scope | |
subject.copywriter_languages.criteria |
OlderNewer