- Why? - To improve performance (that is not call db an each provider request).
- Where? - At the point of fething data from
OfferProvider
component (repositories). - How? - By using
Rails.cache#fetch
Why we don't like caching?
require 'cli_spinnable' | |
module Cli | |
extend CliSpinnable | |
end | |
puts 'HAPPY RUN (should succeed):' | |
Cli.with_spinner do |cli| | |
cli.print 'Downloading something' | |
sleep 1 |
CliSpinnable.with_spinner do |cli| | |
cli.print('Text') #=> / Text | |
cli.tick #=> ✓ Text | |
cli.fail #=> × Text | |
1 / 0 #=> × Text # exceptions raised within the block also triggers printing fail mark | |
end |
class Foo | |
include CliSpinnable | |
def call | |
with_spinner do |cli| | |
#... | |
end | |
end | |
end |
# Step 1. Obtain token | |
curl -X POST \ | |
-F "client_id=b6394b15282889398719c67983594d20" \ | |
-F "client_secret=4aee41059af4d350a6ead3a285f0c438de146857d4134b6e63d5b1291971b12f" \ | |
-F "grant_type=client_credentials" \ | |
-F "scope=write_partner_users" \ | |
'https://berlin.staging.wimdu.com/api/v3/oauth/token' | |
# Step 2. Create user. | |
# fill out <token> (obtained in Step.1) |
module Container | |
# Initialized once (kind'a singleton) | |
def self.a | |
@a ||= Object.new | |
end | |
# Initialized every time. | |
def self.b | |
Object.new | |
end |
def print_translations(hash, phrase_key, i = 0) | |
hash.each do |k, v| | |
if v.is_a?(Hash) | |
i.times { print ' ' } | |
print "#{k.to_s.camelize(:lower)}: {\n"; | |
print_translations(v, "#{phrase_key}.#{k}", i + 1) | |
i.times { print ' ' } | |
print "},\n" | |
else i.times { print ' ' } | |
print "#{k.to_s.camelize(:lower)}: t('#{phrase_key}.#{k}'),\n" |
# Managing own fork | |
### Configure upstream | |
git remote -v | |
git remote add upstream [email protected]:wimdu/wimdu.git | |
### Syncing to upstream | |
git checkout master | |
git fetch upstream master | |
git reset --hard upstream/master |
class A | |
def call | |
# do something | |
end | |
end | |
class B | |
def call(argument) | |
# do something different | |
end |
class CreateUser | |
class Error < StandardError; end | |
# ... | |
end | |
# contoller | |
begin | |
user = CreateUser.new(params).call | |
p "User #{user.username} created succesfully" |