Class: ActionCrud::Helpers::Route
- Inherits:
-
Object
- Object
- ActionCrud::Helpers::Route
- Defined in:
- lib/action_crud/helpers/route.rb
Instance Attribute Summary collapse
-
#action ⇒ Object
Returns the value of attribute action.
-
#options ⇒ Object
Returns the value of attribute options.
-
#path ⇒ Object
Returns the value of attribute path.
-
#record ⇒ Object
Returns the value of attribute record.
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
-
#index? ⇒ Boolean
Is index action.
-
#initialize(context, record = nil, action = nil, *options) ⇒ Route
constructor
Intialize url finder.
-
#prefix? ⇒ Boolean
Should prefix method.
-
#record? ⇒ Boolean
Should include record.
-
#route_key ⇒ Object
Find route key.
-
#route_uri(type) ⇒ Object
Find route method.
-
#to_s(type = :path) ⇒ Object
To string.
Constructor Details
#initialize(context, record = nil, action = nil, *options) ⇒ Route
Intialize url finder
7 8 9 10 11 12 13 14 |
# File 'lib/action_crud/helpers/route.rb', line 7 def initialize(context, record=nil, action=nil, *) @context = context @record = record || @context.try(:current_record) @action = action @options = @path = route_uri :path @url = route_uri :url end |
Instance Attribute Details
#action ⇒ Object
Returns the value of attribute action.
4 5 6 |
# File 'lib/action_crud/helpers/route.rb', line 4 def action @action end |
#options ⇒ Object
Returns the value of attribute options.
4 5 6 |
# File 'lib/action_crud/helpers/route.rb', line 4 def @options end |
#path ⇒ Object
Returns the value of attribute path.
4 5 6 |
# File 'lib/action_crud/helpers/route.rb', line 4 def path @path end |
#record ⇒ Object
Returns the value of attribute record.
4 5 6 |
# File 'lib/action_crud/helpers/route.rb', line 4 def record @record end |
#url ⇒ Object
Returns the value of attribute url.
4 5 6 |
# File 'lib/action_crud/helpers/route.rb', line 4 def url @url end |
Instance Method Details
#index? ⇒ Boolean
Is index action
22 23 24 |
# File 'lib/action_crud/helpers/route.rb', line 22 def index? action == :index end |
#prefix? ⇒ Boolean
Should prefix method
27 28 29 |
# File 'lib/action_crud/helpers/route.rb', line 27 def prefix? action.in? [:new, :edit] end |
#record? ⇒ Boolean
Should include record
32 33 34 |
# File 'lib/action_crud/helpers/route.rb', line 32 def record? action.in? [:show, :edit, :delete, :destroy] end |
#route_key ⇒ Object
Find route key
37 38 39 40 |
# File 'lib/action_crud/helpers/route.rb', line 37 def route_key singular = 'singular_' unless index? record.model_name.try :"#{singular}route_key" end |
#route_uri(type) ⇒ Object
Find route method
43 44 45 46 47 48 49 50 |
# File 'lib/action_crud/helpers/route.rb', line 43 def route_uri(type) args = [*] args = [record, *] if record? method = "#{route_key}_#{type}" method = "#{action}_#{method}" if prefix? @context.try :"#{method}", *args end |
#to_s(type = :path) ⇒ Object
To string
17 18 19 |
# File 'lib/action_crud/helpers/route.rb', line 17 def to_s(type=:path) instance_variable_get("@#{type}").to_s end |