#Report Calc API
##API Abstraction
###Http API
There would be thin html presenter layer that would call the api and hand that off to the view. The api would have a JSON presenter layer.
Pros
| $ sudo irb | |
| irb(main):002:0> require 'fileutils' | |
| => true | |
| irb(main):003:0> FileUtils.rm_rf("#{nil}/") |
#Report Calc API
##API Abstraction
###Http API
There would be thin html presenter layer that would call the api and hand that off to the view. The api would have a JSON presenter layer.
Pros
| class Sharer | |
| def initalizer(stuff_name) | |
| @stuff_name = stuff_name | |
| end | |
| def stuff | |
| @stuff_name | |
| end | |
| class MyClass | |
| def initalize(arg1: arg2:, **additional_args) | |
| post_initalize(**additional_args) | |
| end | |
| def post_initalize(*) | |
| end | |
| end |
| require "thread" | |
| class Thread | |
| alias_method :_initialize, :initialize | |
| def initialize(*args, &block) | |
| inheritable_attributes = Thread.current.inheritable_attributes | |
| _initialize(*args) do | |
| Thread.current.inheritable_attributes = inheritable_attributes | |
| block.call |
| local ret_status="%(?:%{$fg_bold[green]%}➜ :%{$fg_bold[red]%}➜ )" | |
| PROMPT='${ret_status} %{$fg[cyan]%}%c%{$reset_color%}$(travis_status)$(git_prompt_info)' | |
| function travis_status_dir { | |
| GIT_ROOT=`git rev-parse --show-toplevel` | |
| echo "${GIT_ROOT}/tmp/.travis" | |
| } | |
| function travis_status_file { | |
| GIT_SHA=`git rev-parse HEAD` |
| max_stack_frames = 500 | |
| TooManyStackFrames = Class.new(StandardError) | |
| TracePoint.new(:call) do |tp| | |
| if caller.size >= max_stack_frames | |
| raise TooManyStackFrames, "Stack has exceeded #{max_stack_frames} frames" | |
| end | |
| end.enable |
| require "reverse_parameters" | |
| # Converts Object.new(<args>).call to Object.call(<args>) | |
| # module must be extend after initialize method in order to transfer parameters | |
| module CallObject | |
| def create_callable | |
| class_eval(<<-RUBY, __FILE__, __LINE__ + 1) | |
| def self.call(#{ReverseParameters.new(instance_method(:initialize)).parameters}) | |
| self.new(#{ReverseParameters.new(instance_method(:initialize)).arguments}).call | |
| end | |
| RUBY |
| #!/usr/bin/env ruby | |
| require "./config/environment" | |
| require "active_record/migration" | |
| require "tty-prompt" | |
| migration = TTY::Prompt.new(interrupt: :exit) | |
| migration_version = migration.select("Select Migration", filter: true) do |menu| | |
| ActiveRecord::Base.connection.migration_context.migrations_status.reverse.each do |status, version, name| | |
| menu.choice "#{status.center(8)} #{version.ljust(14)} #{name}", version | |
| end |