activerecord-traits 1.0.2 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/traits/model/i18n.rb +12 -0
- data/lib/traits/model/naming.rb +56 -34
- data/lib/traits/model.rb +2 -0
- data/lib/traits/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: 84c79ad24f867dd858de441a1d0bef4d74c847d2
|
4
|
+
data.tar.gz: 9d312a4e8fff3e8330010e1745c687a6a072ce58
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2ec766c0c8f9da4fb1b66e35fdc7e0e02d7b11dc02d71255b3363e8af2843afb6cf0645a60a63fe0cb41ce47ad893fbfe4d1ca18981d946a8078678a7d65edcd
|
7
|
+
data.tar.gz: f3c97ed4ccf20b06b485b8d99b6485bca306b3bba31a6717e2e44e53096695bb3ae47597a3c8f0047ed29c247c132f8fe95ee6aa5f3a022dca217827cb3fb8cf
|
data/lib/traits/model/naming.rb
CHANGED
@@ -5,49 +5,58 @@ module Traits
|
|
5
5
|
class Model
|
6
6
|
module Naming
|
7
7
|
# class User
|
8
|
-
# name
|
8
|
+
# name => user
|
9
|
+
# name(:underscore) => user
|
9
10
|
#
|
10
11
|
# class Assets::Photo
|
11
|
-
# name
|
12
|
+
# name => assets/photo
|
13
|
+
# name(:underscore) => assets_photo
|
12
14
|
#
|
13
|
-
def name
|
14
|
-
# Rails 4.1 doesn't support nested acronyms
|
15
|
+
def name(namecase = nil)
|
16
|
+
# Rails 4.1 doesn't support nested acronyms.
|
15
17
|
#
|
16
|
-
#
|
17
|
-
#
|
18
|
-
#
|
19
|
-
#
|
18
|
+
# Suppose you have:
|
19
|
+
# ActiveSupport::Inflector.inflections(:en) do |inflect|
|
20
|
+
# inflect.acronym 'CI'
|
21
|
+
# end
|
20
22
|
#
|
21
|
-
#
|
22
|
-
#
|
23
|
-
#
|
23
|
+
# Rails 4.1 underscore behaviour:
|
24
|
+
# 'Helpers::ViewHelper' => 'helpers/view_helper' - good
|
25
|
+
# 'CIHelper' => 'ci_helper' - good
|
26
|
+
# 'Helpers::CIHelper' => 'helpers/ci_helper' - good
|
24
27
|
#
|
25
|
-
#
|
26
|
-
#
|
27
|
-
#
|
28
|
-
#
|
28
|
+
# 'Helpers::ViewHelper' => 'helpers/view_helper' - good
|
29
|
+
# 'CIHelper' => 'cihelper' - good
|
30
|
+
# 'Helpers::CIHelper' => 'helpers/ci_helper' - bad
|
31
|
+
#
|
32
|
+
# Newer Rails underscore behaviour:
|
33
|
+
# 'Helpers::ViewHelper' => 'helpers/view_helper' - good
|
34
|
+
# 'CIHelper' => 'cihelper' - good
|
35
|
+
# 'Helpers::CIHelper' => 'helpers/cihelper' - good
|
29
36
|
#
|
30
37
|
@name ||= model_class.name.split('::').map(&:underscore).join('/')
|
38
|
+
if namecase == :underscore
|
39
|
+
@underscore_name ||= @name.tr('/', '_')
|
40
|
+
else
|
41
|
+
@name
|
42
|
+
end
|
31
43
|
end
|
32
44
|
|
33
45
|
# class User
|
34
|
-
# plural_name
|
46
|
+
# plural_name => users
|
47
|
+
# plural_name(:underscore) => users
|
35
48
|
#
|
36
49
|
# class Assets::Photo
|
37
|
-
# plural_name
|
50
|
+
# plural_name => assets/photos
|
51
|
+
# plural_name(:underscore) => assets_photos
|
38
52
|
#
|
39
|
-
def plural_name
|
53
|
+
def plural_name(namecase = nil)
|
40
54
|
@plural_name ||= name.pluralize
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
# class Assets::Photo
|
47
|
-
# resource_name => assets/photos
|
48
|
-
#
|
49
|
-
def resource_name
|
50
|
-
@resource_name ||= plural_name
|
55
|
+
if namecase == :underscore
|
56
|
+
@plural_underscore_name ||= @plural_name.tr('/', '_')
|
57
|
+
else
|
58
|
+
@plural_name
|
59
|
+
end
|
51
60
|
end
|
52
61
|
|
53
62
|
# class User
|
@@ -61,17 +70,30 @@ module Traits
|
|
61
70
|
end
|
62
71
|
|
63
72
|
# class User
|
64
|
-
# lookup_name
|
73
|
+
# lookup_name => User
|
65
74
|
# lookup_name(:underscore) => user
|
66
75
|
#
|
67
76
|
# class Assets::Photo
|
68
|
-
# lookup_name
|
77
|
+
# lookup_name => AssetsPhoto
|
69
78
|
# lookup_name(:underscore) => assets_photo
|
70
79
|
#
|
71
|
-
def lookup_name(namecase =
|
72
|
-
namecase == :underscore
|
73
|
-
|
74
|
-
|
80
|
+
def lookup_name(namecase = nil)
|
81
|
+
if namecase == :underscore
|
82
|
+
name(namecase)
|
83
|
+
else
|
84
|
+
@lookup_name ||= class_name.tr('::', '')
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
# TODO Deprecate?
|
89
|
+
# class User
|
90
|
+
# resource_name => users
|
91
|
+
#
|
92
|
+
# class Assets::Photo
|
93
|
+
# resource_name => assets/photos
|
94
|
+
#
|
95
|
+
def resource_name
|
96
|
+
@resource_name ||= plural_name
|
75
97
|
end
|
76
98
|
|
77
99
|
def to_hash
|
data/lib/traits/model.rb
CHANGED
@@ -11,6 +11,7 @@ require 'traits/model/polymorphism'
|
|
11
11
|
require 'traits/model/inheritance'
|
12
12
|
require 'traits/model/querying'
|
13
13
|
require 'traits/model/essay_shortcuts'
|
14
|
+
require 'traits/model/i18n'
|
14
15
|
|
15
16
|
module Traits
|
16
17
|
class Model
|
@@ -19,6 +20,7 @@ module Traits
|
|
19
20
|
include Polymorphism
|
20
21
|
include Querying
|
21
22
|
include EssayShortcuts
|
23
|
+
include I18n
|
22
24
|
|
23
25
|
attr_reader :model_class
|
24
26
|
|
data/lib/traits/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord-traits
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yaroslav Konoplov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-10-
|
11
|
+
date: 2016-10-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -87,6 +87,7 @@ files:
|
|
87
87
|
- lib/traits/list.rb
|
88
88
|
- lib/traits/model.rb
|
89
89
|
- lib/traits/model/essay_shortcuts.rb
|
90
|
+
- lib/traits/model/i18n.rb
|
90
91
|
- lib/traits/model/inheritance.rb
|
91
92
|
- lib/traits/model/naming.rb
|
92
93
|
- lib/traits/model/polymorphism.rb
|