Sha256: 3850d8525d139afb8b7f9235a7582f78d6aa13152fb39a1c6d40d31ccda8472b
Contents?: true
Size: 1.9 KB
Versions: 8
Compression:
Stored size: 1.9 KB
Contents
module <%= class_name %> include Chanko::Unit # ## active_if # This block is used to decide if this unit is active or not. # `context` is the receiver object of `invoke`. # `options` is passed via `invoke(:foo, :bar, :active_if_options => { ... })`. # By default, this is set as `active_if { true }`. # # ``` # active_if do |context, options| # true # end # ``` # ## raise_error # `raise_error` is used to force an unit to raise up errors occured in invoking. # You can force to raise up errors also by `Config.raise_error`. # # ``` # raise_error # ``` # ## function # In controller or view context, you can call functions defined by `function` # via `invoke(:<%= file_name %>, :function_name)`. # # ``` # scope(:controller) do # function(:function_name) do # "Chanko!" # end # end # ``` # ## render # In addition, the view path "<%= "#{directory}/views" %>" is added into view_paths. # So you can render <%= "#{directory}/views/_example.html.erb" %> in invoking. # # ``` # scope(:view) do # function(:function_name) do # render "/example", :foo => "bar" # end # end # ``` # ## models # In models block, you can expand model features by `expand` method. # The expanded methods are available via unit proxy like `User.unit.active`, # and `User.find(params[:id]).unit.active?`, and so on. # # ``` # models do # expand(:User) do # scope :active, lambda { where(:deleted_at => nil) } # # def active? # deleted_at.nil? # end # end # end # ``` # ## shared # You can call methods defined by `shared` in invoking. # # ``` # shared(:hello) do |world| # "Hello, #{world}" # end # ``` # ## helpers # You can call helpers in view via unit proxy like `unit.helper_method` # # ``` # helpers do # def helper_method # "helper method" # end # end # ``` end
Version data entries
8 entries across 8 versions & 1 rubygems