rails_stuff 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -1
- data/CHANGELOG.md +4 -0
- data/Gemfile +1 -0
- data/README.md +3 -0
- data/lib/rails_stuff/helpers/resource_form.rb +5 -3
- data/lib/rails_stuff/types_tracker.rb +14 -2
- data/lib/rails_stuff/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b4d05c4a1131bbc5cf6e653451d50aa7f09a2902
|
4
|
+
data.tar.gz: 7463af96e7f8c64b3399fb6ce6e9c701b852533a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 51871432200910ce3c7e71f4cad3f4112a87c5ddba4bae34a773b179192333e6e1ace524337f8ae23fc9a22d51eaf03c3efca4b202e019f55cb2d294c6c0770e
|
7
|
+
data.tar.gz: 439fa7ded29c96cf88db521c40c6a60039d8f6db7e74fe961cbebe97c9e907f9e8f875ec5369eb1abba3e0d1f5de6ec04f4298c7943e5b0f709814769a3c6660
|
data/.rubocop.yml
CHANGED
@@ -19,6 +19,6 @@ Style/SignalException: {EnforcedStyle: only_raise}
|
|
19
19
|
Style/SpaceInsideHashLiteralBraces: {EnforcedStyle: no_space}
|
20
20
|
Style/TrailingComma: {Enabled: false}
|
21
21
|
|
22
|
-
Metrics/AbcSize: {Max:
|
22
|
+
Metrics/AbcSize: {Max: 21}
|
23
23
|
Metrics/LineLength: {Max: 100}
|
24
24
|
Metrics/MethodLength: {Max: 30}
|
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -37,9 +37,11 @@ module RailsStuff
|
|
37
37
|
msg = f.object.errors[:base].first
|
38
38
|
html << content_tag(:div, msg, class: 'alert alert-danger') if msg
|
39
39
|
html << capture { yield(f) }
|
40
|
-
html <<
|
41
|
-
|
42
|
-
|
40
|
+
html << content_tag(:div, class: 'form-group') do
|
41
|
+
inputs = f.button(:submit, class: 'btn-primary')
|
42
|
+
inputs << ' '
|
43
|
+
inputs << link_to(translate_action(:cancel), back_url, class: :btn)
|
44
|
+
end
|
43
45
|
end
|
44
46
|
end
|
45
47
|
RUBY
|
@@ -11,6 +11,7 @@ module RailsStuff
|
|
11
11
|
def extended(base)
|
12
12
|
base.class_attribute :types_list, instance_accessor: false
|
13
13
|
base.types_list = types_list_class.new
|
14
|
+
base.instance_variable_set(:@_types_tracker_base, base)
|
14
15
|
end
|
15
16
|
|
16
17
|
# Class for `types_list`. Default to `Array`. You can override it
|
@@ -21,16 +22,22 @@ module RailsStuff
|
|
21
22
|
|
22
23
|
self.types_list_class = Array
|
23
24
|
|
24
|
-
# Add `self` to `types_list`.
|
25
|
+
# Add `self` to `types_list`. Defines scope for ActiveRecord models.
|
25
26
|
def register_type(*args)
|
26
27
|
if types_list.respond_to?(:add)
|
27
28
|
types_list.add self, *args
|
28
29
|
else
|
29
30
|
types_list << self
|
30
31
|
end
|
32
|
+
if types_tracker_base.respond_to?(:scope) && # rubocop:disable GuardClause
|
33
|
+
!types_tracker_base.respond_to?(model_name.element)
|
34
|
+
type_name = name
|
35
|
+
types_tracker_base.scope model_name.element, -> { where(type: type_name) }
|
36
|
+
end
|
31
37
|
end
|
32
38
|
|
33
|
-
# Remove `self` from `types_list`.
|
39
|
+
# Remove `self` from `types_list`. It doesnt remove generated scope
|
40
|
+
# from ActiveRecord models, 'cause it potentialy can remove other methods.
|
34
41
|
def unregister_type
|
35
42
|
types_list.delete self
|
36
43
|
end
|
@@ -46,5 +53,10 @@ module RailsStuff
|
|
46
53
|
super
|
47
54
|
base.register_type
|
48
55
|
end
|
56
|
+
|
57
|
+
# Class that was initilly extended with TypesTracker.
|
58
|
+
def types_tracker_base
|
59
|
+
@_types_tracker_base || superclass.types_tracker_base
|
60
|
+
end
|
49
61
|
end
|
50
62
|
end
|
data/lib/rails_stuff/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_stuff
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Max Melentiev
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-10-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -129,3 +129,4 @@ signing_key:
|
|
129
129
|
specification_version: 4
|
130
130
|
summary: Collection of useful modules for Rails
|
131
131
|
test_files: []
|
132
|
+
has_rdoc:
|