Class: ActiveManageable::Base
- Inherits:
-
Object
- Object
- ActiveManageable::Base
- Defined in:
- lib/active_manageable/base.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#current_method ⇒ Object
readonly
Returns the value of attribute current_method.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#target ⇒ Object
Returns the value of attribute target.
Class Method Summary collapse
-
.inherited(subclass) ⇒ Object
Ruby method called when a child class inherits from a parent class.
-
.manageable(*methods) ⇒ Object
Include the required action methods in your class either all methods using the ActiveManageable::ALL_METHODS constant or selective methods from :index, :show, :new, :create, :edit, :update, :destroy and optionally set the :model_class.
Instance Method Summary collapse
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
8 9 10 |
# File 'lib/active_manageable/base.rb', line 8 def attributes @attributes end |
#current_method ⇒ Object (readonly)
Returns the value of attribute current_method.
8 9 10 |
# File 'lib/active_manageable/base.rb', line 8 def current_method @current_method end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
8 9 10 |
# File 'lib/active_manageable/base.rb', line 8 def @options end |
#target ⇒ Object
Returns the value of attribute target.
7 8 9 |
# File 'lib/active_manageable/base.rb', line 7 def target @target end |
Class Method Details
.inherited(subclass) ⇒ Object
Ruby method called when a child class inherits from a parent class
17 18 19 20 21 22 23 |
# File 'lib/active_manageable/base.rb', line 17 def inherited(subclass) super # necessary to set default value here rather than in class_attribute declaration # otherwise all subclasses share the same hash/array instance subclass.defaults = {} subclass.module_initialize_state_methods = [] end |
.manageable(*methods) ⇒ Object
Include the required action methods in your class either all methods using the ActiveManageable::ALL_METHODS constant or selective methods from :index, :show, :new, :create, :edit, :update, :destroy and optionally set the :model_class
For example:-
manageable ActiveManageable::ALL_METHODS
manageable ActiveManageable::ALL_METHODS, model_class: Album
manageable :index, :show
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/active_manageable/base.rb', line 36 def manageable(*methods) = methods..dup methods = ActiveManageable::Methods.constants if methods[0] == ActiveManageable::ALL_METHODS methods.each do |method| include ActiveManageable::Methods.const_get(method.to_s.classify) end include_search include_pagination .each { |key, value| send(:"#{key}=", value) } set_model_class end |
Instance Method Details
#current_user ⇒ Object
106 107 108 |
# File 'lib/active_manageable/base.rb', line 106 def current_user @current_user || ActiveManageable.current_user end |
#with_current_user(user) ⇒ Object
110 111 112 113 114 115 |
# File 'lib/active_manageable/base.rb', line 110 def with_current_user(user) @current_user = user yield ensure @current_user = nil end |