Chanko Hacking Guide

Chanko Hacking Guide

089127ffb92a19d3d37815673cca06dc?s=128

r7kamura

April 28, 2014
Tweet

Transcript

  1. CHG Chanko Hacking Guide @r7kamura

  2. 1. README.md 2. chanko.gemspec 3. lib/chanko.rb 4. lib/chanko/railtie.rb 5. lib/chanko/invoker.rb

    6. lib/chanko/loader.rb 7. lib/chanko/function.rb
  3. README.md Chanko ! Chanko provides a simple framework for rapidly

    and safely prototyping new features in your production Rails app, and exposing these prototypes to specified segments of your user base. ! With Chanko, you can release many features concurrently and manage target users independently. When any errors are raised from chanko's features, it will be automatically hidden and fallback to its normal behavior.
  4. README.md = invoke(:unit_name, :function_name) do # fallback …

  5. rails >= 3.0.10 chanko.gemspec

  6. Bundler.require Loads all Gems listed in Gemfile. Open your config/application.rb

    to see the real example. ! # example Bundler.require(:default, Rails.env)
  7. require "action_controller" require "action_view" require "active_record" require "active_support/all" require "rails"

    require "chanko/active_if" require "chanko/config" require "chanko/controller" require "chanko/exception_handler" require "chanko/function" require "chanko/helper" require "chanko/invoker" require "chanko/loader" require "chanko/logger" require "chanko/railtie" require "chanko/unit" require "chanko/unit_proxy" require "chanko/unit_proxy_provider" lib/chanko.rb external internal
  8. Rails::Railtie Railtie is the core of the Rails framework and

    provides several hooks to extend Rails and/or modify the initialization process. ! class MyRailtie < Rails::Railtie initializer "my_initializer_name" do # some initialization behavior end end
  9. Rails Init Process 1. `rails s` 2. bin/rails 3. rails/commands/server

    … or using unicorn 4. config.ru 5. config/application.rb 6. Bundler.require 7. My::Application.initialize! 8. initializers.tsort_each… 9. run My::Application
  10. initializer "chanko" do ActionController::Base.include Controller ActionController::Base.include Invoker ActionController::Base.include UnitProxyProvider ActionView::Base.include

    Helper ActionView::Base.include Invoker ActionView::Base.include UnitProxyProvider end lib/chanko/railtie.rb
  11. .invoke(:x, :y) 1. find a module named “X” 2. find

    a function named “y” from “X” 3. stack local variables 4. call “y” 5. unstack local variables 6. call fallback block if any error occurred lib/chanko/invoker.rb
  12. Loader.load(name) 1. autoload_paths << app/extensions/#{name} 2. name.camelize.constantize 3. rescue Exception

    lib/chanko/loader.rb
  13. AS::Dependencies 1. Register auto load path 2. Find module if

    const_missing occurred 3. Clear loaded modules if any file changed
  14. lib/chanko/invoker.rb view.invoke(:x, :y) Loader.load(:x) AS::Dependencies “X”.constantize Loader.cache .clear in each

    request in development
  15. lib/chanko/invoker.rb view.invoke(:x, :y) X.find_function(view, :y) function.invoke(view) view.instance_eval X.scopes[view][:y] module X

    scopes(:view) { function(:y) { … } } end function.active?
  16. lib/chanko/function.rb instance _eval decoration exception handler view path stack unit

    stack fallback stack
  17. Thank you github.com/cookpad/chanko