enum_ext 0.1.5 → 0.1.6
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/Gemfile.lock +1 -1
- data/README.md +3 -0
- data/lib/enum_ext/version.rb +1 -1
- data/lib/enum_ext.rb +4 -0
- 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: 498c9ea4cd953c9d1ec4248bd1ca79dd8900a69e
|
4
|
+
data.tar.gz: 126cefcb0924422ddb47f362a3846987e4c5ac71
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 418057bbc8521469d070187b9cc44668976ff0b6180104ea5a339e194e1fb99528c495ff61e7141e59725267cdbdbf2be0b6d96838ad2553eb8cd4a6df881c7b
|
7
|
+
data.tar.gz: fafaeab39aa49ddccdc776dd4fe2d8313ba86fa61828223f7139747a7fc008b1eab14210fb835efebb63f8c371f9fc465bb91e0e13ad1f5d9742ebefa083a7cb
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -70,6 +70,7 @@ Console:
|
|
70
70
|
request.status # >> payed
|
71
71
|
request.t_status # >> "Payed 3 dollars"
|
72
72
|
Request.t_statuses # >> { in_cart: -> { I18n.t("request.status.in_cart") }, .... }
|
73
|
+
Request.t__
|
73
74
|
|
74
75
|
If you need some substitution you can go like this:
|
75
76
|
|
@@ -84,6 +85,7 @@ If you need select status on form:
|
|
84
85
|
|
85
86
|
f.select :status, Request.t_statuses.invert.to_a
|
86
87
|
|
88
|
+
Works with ext_enum_sets, slicing t_enum_set from original set of enum values
|
87
89
|
|
88
90
|
### Enum Sets (ext_enum_sets)
|
89
91
|
|
@@ -99,6 +101,7 @@ If you need select status on form:
|
|
99
101
|
#scopes: non_payed, delivery_set, in_warehouse
|
100
102
|
#scopes: with_statuses, without_statuses
|
101
103
|
#class methods: non_payed_statuses, delivery_set_statuses ( = [:in_cart, :waiting_for_payment], [:ready_for_shipment, :on_delivery, :delivered].. )
|
104
|
+
#class methods: t_non_payed_statuses, t_delivery_set_statuses ( = {in_cart: "In cart localization" ...} )
|
102
105
|
|
103
106
|
ext_enum_sets :status, {
|
104
107
|
non_payed: [:in_cart, :waiting_for_payment],
|
data/lib/enum_ext/version.rb
CHANGED
data/lib/enum_ext.rb
CHANGED
@@ -122,6 +122,10 @@ module EnumExt
|
|
122
122
|
self.send(enum_name) && ( enum_vals.include?( self.send(enum_name) ) || enum_vals.include?( self.send(enum_name).to_sym ))
|
123
123
|
end
|
124
124
|
|
125
|
+
define_singleton_method( "t_#{set_name}_#{enum_name.to_s.pluralize}" ) do
|
126
|
+
self.send( "t_#{enum_name.to_s.pluralize}" ).slice( *self.send("#{set_name}_#{enum_name.to_s.pluralize}") ) if self.respond_to?("t_#{enum_name.to_s.pluralize}")
|
127
|
+
end
|
128
|
+
|
125
129
|
end
|
126
130
|
|
127
131
|
scope "with_#{enum_name.to_s.pluralize}", -> (sets_arr) {
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: enum_ext
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- alekseyl
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-10-
|
11
|
+
date: 2016-10-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|