Module: Faalis::Dashboard::Sections::Resource::ClassMethods
- Defined in:
- lib/faalis/dashboard/sections/resource.rb
Overview
The actual DSL for resource ages
Instance Method Summary collapse
-
#engine(name) ⇒ Object
Set the engine name of current controller.
-
#model_class ⇒ Object
Returns the actual model class by looking at ‘controller_name` and and `controller_path`.
-
#model_name(name) ⇒ Object
Specify the model name of controller.
-
#route_engine(name = nil, &block) ⇒ Object
Via this method user can specify the engine or application name which current resource is defined under.
-
#route_namespace(name, &block) ⇒ Object
Using this method user can override the route namespace guessed by Faalis.
-
#route_scope(name, &block) ⇒ Object
Via this method user can specify the name of current resource scope, Default value is ‘dashboard`.
Instance Method Details
#engine(name) ⇒ Object
Set the engine name of current controller. It’s necessary to provide and engine name if the controller belongs to an engine other than Faalis or Rails.application.
198 199 200 201 202 |
# File 'lib/faalis/dashboard/sections/resource.rb', line 198 def engine(name) define_method(:_engine) do name.constantize end end |
#model_class ⇒ Object
Returns the actual model class by looking at ‘controller_name` and and `controller_path`. If user uses the `model_name` **class method** (the `model_name` DSL) then this method will override by the `model_name` defination of `model_class`
220 221 222 223 224 225 |
# File 'lib/faalis/dashboard/sections/resource.rb', line 220 def model_class name = controller_name path = controller_path.gsub(name, '').gsub(/dashboard\//, '') "#{path}#{name}".classify.constantize end |
#model_name(name) ⇒ Object
Specify the model name of controller. This method overrides the ‘model_class` **class method** and `model_name` instance method.
206 207 208 209 210 211 212 213 214 |
# File 'lib/faalis/dashboard/sections/resource.rb', line 206 def model_name(name) define_singleton_method :model_class do name.constantize end define_method :model_name do name end end |
#route_engine(name = nil, &block) ⇒ Object
Via this method user can specify the engine or application name which current resource is defined under. Default value is: Rails.application
170 171 172 173 174 175 176 |
# File 'lib/faalis/dashboard/sections/resource.rb', line 170 def route_engine(name = nil, &block) define_method(:_route_engine) do return block.call if block_given? return name unless name.nil? fail 'You have to provide a name or a block' end end |
#route_namespace(name, &block) ⇒ Object
Using this method user can override the route namespace guessed by Faalis.
189 190 191 192 193 194 |
# File 'lib/faalis/dashboard/sections/resource.rb', line 189 def route_namespace(name, &block) define_method(:_namespace) do return block.call if block_given? name end end |
#route_scope(name, &block) ⇒ Object
Via this method user can specify the name of current resource scope, Default value is ‘dashboard`
180 181 182 183 184 185 |
# File 'lib/faalis/dashboard/sections/resource.rb', line 180 def route_scope(name, &block) define_method(:_route_scope) do return block.call if block_given? name end end |