action_crud 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 31a0e2593bbdae590abea1ce539011e21fdd36c3
4
- data.tar.gz: 9fc1280a4be0878bd1397c68ad44073b6f54d3cd
3
+ metadata.gz: 2bec677719c37b510e60fd122623b1b5ca4bb7f1
4
+ data.tar.gz: ee0acbd7660e0b4ce61f3aba0e8df935d63468bd
5
5
  SHA512:
6
- metadata.gz: 5d2c154c7ebc4d3fbc09d7a5ad7398e0fbbb106eefcd42881baa1fc2cfcefca3a2ed829c2f0a447372680ee2c2c4520addede041906ce2315fcb81f3fa04c6df
7
- data.tar.gz: 415a63a957abee12b31c92eb8c671e635c81d7d8d3232fe5c658c65d0700061ea323e9a39ab6f2b4d005dc18f5c57d4fe91c73ea8c2a14a1b735e7882c899fc6
6
+ metadata.gz: 5cd7315126fe152cf5575ab417fd73ea357622d403b43089e255a85fa289d5d45865c7c8a4f3cc1ec050c6c9e526312b5c6efa350621972b4d0c5991b11854c3
7
+ data.tar.gz: c7362315dbaf55802ab75f05f75220672e434508b5d6a082b0738c5d1f2c62dbaa54eb9ea84212e0d10baf69062206fa970b15aafd404a15ae4597c24194a352
@@ -16,7 +16,6 @@ module ActionCrud
16
16
 
17
17
  # Set class attributes
18
18
  set_model_name
19
- set_model_class
20
19
  set_index_scope
21
20
 
22
21
  # Action callbacks
@@ -27,7 +26,8 @@ module ActionCrud
27
26
  class_methods do
28
27
  # Set permitted parameters
29
28
  def permit_params(options={})
30
- default = { only: model_class.attribute_names, except: [], also: [], array: [], hash: [] }
29
+ attribs = model_class.try(:attribute_names).to_a
30
+ default = { only: attribs, except: [], also: [], array: [], hash: [] }
31
31
  options = Hash[default.merge(options).map { |k, v| [k, Array(v).map(&:to_sym)] }]
32
32
  permit = options.except(:except).values.flatten.uniq
33
33
 
@@ -40,12 +40,16 @@ module ActionCrud
40
40
 
41
41
  # Set model name
42
42
  def set_model_name(name=nil)
43
- name = name || controller_name.classify
43
+ name = name || _guess_controller_model
44
44
  name = name.constantize if name.is_a? String
45
45
 
46
- self.model_name = name.model_name
47
- self.instance_name = model_name.singular
48
- self.collection_name = model_name.plural
46
+ unless name.nil?
47
+ self.model_name = name.model_name
48
+ self.instance_name = model_name.singular
49
+ self.collection_name = model_name.plural
50
+
51
+ set_model_class
52
+ end
49
53
  end
50
54
 
51
55
  # Set model class
@@ -58,6 +62,13 @@ module ActionCrud
58
62
  def set_index_scope(scope='all')
59
63
  self.index_scope = scope.to_sym
60
64
  end
65
+
66
+ private
67
+
68
+ def _guess_controller_model
69
+ controller_name.classify.safe_constantize ||
70
+ name.sub(/controller/i, '').classify.safe_constantize
71
+ end
61
72
  end
62
73
 
63
74
  # GET /model
@@ -1,3 +1,3 @@
1
1
  module ActionCrud
2
- VERSION = '0.1.3'
2
+ VERSION = '0.1.4'
3
3
  end
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.3
4
+ version: 0.1.4
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-10-20 00:00:00.000000000 Z
11
+ date: 2017-11-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack