action_crud 0.1.4 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/action_crud/controller.rb +13 -2
- data/lib/action_crud/helpers/link.rb +2 -0
- data/lib/action_crud/helpers/route.rb +39 -23
- data/lib/action_crud/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d00252806780a27d33fe1a5e0da095fc3800fc9a
|
4
|
+
data.tar.gz: 5f474851b6b228f456d0e52c7a8c3598e89b3b8a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 419b05fb125bdbf81933f2bbecd47a3e6e9960926b196ebfba20fabb7f3c7615d03dbef53bb77b85a778b2d110ff340ed2198a9fd371e42a2669cb607967be4f
|
7
|
+
data.tar.gz: d4c84b8008fc65dd9b15d757c33a465774d69738c387848605887bd4fd34437d52ff54df125c19df5ce0ac99dbac19ce16cd0829b2e52cc0d8b2d9a539a9243f
|
@@ -4,6 +4,7 @@ module ActionCrud
|
|
4
4
|
|
5
5
|
included do
|
6
6
|
# Class attributes
|
7
|
+
class_attribute :namespace, instance_predicate: false
|
7
8
|
class_attribute :model_name, instance_predicate: false
|
8
9
|
class_attribute :model_class, instance_predicate: false
|
9
10
|
class_attribute :instance_name, instance_predicate: false
|
@@ -38,6 +39,12 @@ module ActionCrud
|
|
38
39
|
self.permitted_params = permit
|
39
40
|
end
|
40
41
|
|
42
|
+
# Set namespace to remove from model
|
43
|
+
def set_namespace(name=nil)
|
44
|
+
self.namespace = name
|
45
|
+
set_model_name
|
46
|
+
end
|
47
|
+
|
41
48
|
# Set model name
|
42
49
|
def set_model_name(name=nil)
|
43
50
|
name = name || _guess_controller_model
|
@@ -66,8 +73,12 @@ module ActionCrud
|
|
66
73
|
private
|
67
74
|
|
68
75
|
def _guess_controller_model
|
69
|
-
|
70
|
-
|
76
|
+
if namespace.nil?
|
77
|
+
controller_name.classify.safe_constantize ||
|
78
|
+
name.gsub(/controller$/i, '').classify.safe_constantize
|
79
|
+
else
|
80
|
+
name.gsub(/^#{namespace.to_s}|controller$/i, '').classify.safe_constantize
|
81
|
+
end
|
71
82
|
end
|
72
83
|
end
|
73
84
|
|
@@ -39,6 +39,8 @@ module ActionCrud
|
|
39
39
|
actions = args.concat(action).concat(options.keys)
|
40
40
|
links = actions.uniq.map do |item|
|
41
41
|
args = Hash(options[item]).reverse_merge(default)
|
42
|
+
args = args.merge(class: "#{default[:class]} #{args[:class]}".strip)
|
43
|
+
|
42
44
|
ActionCrud::Helpers::Link.new(@context, record, item, args).render
|
43
45
|
end
|
44
46
|
|
@@ -1,16 +1,16 @@
|
|
1
1
|
module ActionCrud
|
2
2
|
module Helpers
|
3
3
|
class Route
|
4
|
-
attr_accessor :record, :action, :options, :path, :url
|
4
|
+
attr_accessor :model, :record, :action, :options, :path, :url
|
5
5
|
|
6
6
|
# Intialize url finder
|
7
7
|
def initialize(context, record=nil, action=nil, *options)
|
8
8
|
@context = context
|
9
9
|
@record = record || @context.try(:current_record)
|
10
10
|
@action = action
|
11
|
-
@options = options
|
12
|
-
@path = route_uri
|
13
|
-
@url = route_uri
|
11
|
+
@options = Hash(options.first)
|
12
|
+
@path = route_uri true
|
13
|
+
@url = route_uri false
|
14
14
|
end
|
15
15
|
|
16
16
|
# To string
|
@@ -18,35 +18,51 @@ module ActionCrud
|
|
18
18
|
instance_variable_get("@#{type}").to_s
|
19
19
|
end
|
20
20
|
|
21
|
-
#
|
22
|
-
def
|
23
|
-
action
|
21
|
+
# Should include record
|
22
|
+
def record?
|
23
|
+
action.in? [:show, :edit, :delete, :destroy]
|
24
24
|
end
|
25
25
|
|
26
|
-
#
|
27
|
-
def
|
28
|
-
|
26
|
+
# Get model name
|
27
|
+
def model(method='singular')
|
28
|
+
unless @record.nil?
|
29
|
+
@record.class.model_name.send(method).to_sym
|
30
|
+
end
|
29
31
|
end
|
30
32
|
|
31
|
-
#
|
32
|
-
def
|
33
|
-
|
33
|
+
# Get route namespace
|
34
|
+
def namespace
|
35
|
+
if @context.respond_to? :controller
|
36
|
+
@context.controller.try(:namespace)
|
37
|
+
else
|
38
|
+
@context.try(:namespace)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
# Get namespaced record
|
43
|
+
def namespaced_record
|
44
|
+
if action == :edit
|
45
|
+
namespace.present? ? [:edit, namespace, record] : [:edit, record]
|
46
|
+
else
|
47
|
+
namespace.present? ? [namespace, record] : [record]
|
48
|
+
end
|
34
49
|
end
|
35
50
|
|
36
|
-
#
|
37
|
-
def
|
38
|
-
|
39
|
-
|
51
|
+
# Get namespaced model
|
52
|
+
def namespaced_model
|
53
|
+
if action == :new
|
54
|
+
namespace.present? ? [:new, namespace, model] : [:new, model]
|
55
|
+
else
|
56
|
+
namespace.present? ? [namespace, model('plural')] : model('plural')
|
57
|
+
end
|
40
58
|
end
|
41
59
|
|
42
60
|
# Find route method
|
43
|
-
def route_uri(
|
44
|
-
args
|
45
|
-
args
|
46
|
-
method = "#{route_key}_#{type}"
|
47
|
-
method = "#{action}_#{method}" if prefix?
|
61
|
+
def route_uri(only_path=false)
|
62
|
+
args = record? ? namespaced_record : namespaced_model
|
63
|
+
args = [args, options.merge(only_path: only_path)].flatten.reject(&:blank?)
|
48
64
|
|
49
|
-
@context.
|
65
|
+
@context.url_for(args)
|
50
66
|
end
|
51
67
|
end
|
52
68
|
end
|
data/lib/action_crud/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: action_crud
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jonian Guveli
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-12-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionpack
|