Sha256: 826f0d5c5390b9176ce9f85f22ea90d769cf1a62fd77d4b5aac1ea9a258028f3

Contents?: true

Size: 1.98 KB

Versions: 2

Compression:

Stored size: 1.98 KB

Contents

module <%= class_name %>
  include Nyanko::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
  #     "Nyanko!"
  #   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(:controller) 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.
  #
  # ```
  # scope(:view) do
  #   function(:function_name) do
  #     hello
  #   end
  # end
  #
  # 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

2 entries across 2 versions & 1 rubygems

Version Path
nyanko-0.0.9 lib/generators/nyanko/unit/templates/unit.rb.erb
nyanko-0.0.8 lib/generators/nyanko/unit/templates/unit.rb.erb