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_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.
211 212 213 214 215 |
# File 'lib/faalis/dashboard/sections/resource.rb', line 211 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`
233 234 235 236 237 238 |
# File 'lib/faalis/dashboard/sections/resource.rb', line 233 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.
219 220 221 222 223 224 225 226 227 |
# File 'lib/faalis/dashboard/sections/resource.rb', line 219 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
191 192 193 194 195 196 197 |
# File 'lib/faalis/dashboard/sections/resource.rb', line 191 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_scope(name, &block) ⇒ Object
Via this method user can specify the name of current resource scope, Default value is ‘dashboard`
201 202 203 204 205 206 |
# File 'lib/faalis/dashboard/sections/resource.rb', line 201 def route_scope(name, &block) define_method(:_route_scope) do return block.call if block_given? name end end |