enum_ext 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +9 -8
- data/enum_ext.gemspec +0 -1
- data/lib/enum_ext/version.rb +1 -1
- data/lib/enum_ext.rb +3 -3
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2f27d12cb86814ebce65a02477dd28e5ca255fef
|
4
|
+
data.tar.gz: 5cdcca46d7df13ab534352b74f70f0d8899446db
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c89e5517d0cc30afb3c754bc29e6aebc32eda62437f440f17cc32da3daa5abf797c7cdd605a8ec87121c8fd8daaa773b5fd64f6d48d0d7ec899d9e4a605add4e
|
7
|
+
data.tar.gz: 1023069a48375dd626f6aa63b9a9b53d40e7dadd7ba71add171447274bfa76b51d55f0af90baf2d4baffd182d8b7043789ff3261dbe6db4326d1bb2b871c624b
|
data/README.md
CHANGED
@@ -74,21 +74,19 @@ If you need select status on form and so:
|
|
74
74
|
|
75
75
|
|
76
76
|
### Enum Sets (ext_enum_sets)
|
77
|
-
|
78
|
-
This method intended for creating and using some sets of enum values with similar to original enum syntax.
|
79
77
|
|
80
|
-
**Use-case** For example you have pay bills of different types, and you want to group some types in debit and credit "super-types", and have scope PayBill.debit, instance method with question mark as usual enum does pay_bill.debit
|
78
|
+
**Use-case** For example you have pay bills of different types, and you want to group some types in debit and credit "super-types", and have scope PayBill.debit, instance method with question mark as usual enum does pay_bill.debit?.
|
81
79
|
|
82
80
|
You can do this with method **ext_enum_sets**, it creates: scopes for subsets like enum did, instance method with ? similar to enum methods, and so...
|
83
81
|
|
84
|
-
I strongly recommend you to create
|
82
|
+
I strongly recommend you to create special comment near method call, to remember what methods will be defined on instance, on class itself, and what scopes will be defined
|
85
83
|
|
86
84
|
class Request
|
87
85
|
...
|
88
|
-
#instance non_payed?, delivery_set?, in_warehouse?
|
86
|
+
#instance: non_payed?, delivery_set?, in_warehouse?
|
89
87
|
#class scopes: non_payed, delivery_set, in_warehouse
|
90
88
|
#class scopes: with_statuses, without_statuses
|
91
|
-
#class non_payed_statuses, delivery_set_statuses ( = [:in_cart, :waiting_for_payment], [:ready_for_shipment, :on_delivery, :delivered].. )
|
89
|
+
#class: non_payed_statuses, delivery_set_statuses ( = [:in_cart, :waiting_for_payment], [:ready_for_shipment, :on_delivery, :delivered].. )
|
92
90
|
|
93
91
|
ext_enum_sets :status, {
|
94
92
|
non_payed: [:in_cart, :waiting_for_payment],
|
@@ -146,9 +144,12 @@ You can call ext_enum_sets more than one time defining a superposition of alread
|
|
146
144
|
request1.updated_at # >> ~ Time.now
|
147
145
|
Request.respond_to?('::MassAssignEnum') # >> true
|
148
146
|
|
149
|
-
|
147
|
+
|
148
|
+
order.requests.already_payed.count # >> N
|
149
|
+
order.requests.delivered.count # >> M
|
150
150
|
order.requests.already_payed.delivered!
|
151
|
-
order.requests.
|
151
|
+
order.requests.already_payed.count # >> 0
|
152
|
+
order.requests.delivered.count # >> N + M
|
152
153
|
|
153
154
|
|
154
155
|
####Rem:
|
data/enum_ext.gemspec
CHANGED
@@ -14,7 +14,6 @@ Gem::Specification.new do |spec|
|
|
14
14
|
spec.homepage = "https://github.com/alekseyl/enum_ext"
|
15
15
|
spec.license = "MIT"
|
16
16
|
|
17
|
-
|
18
17
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
19
18
|
spec.bindir = "exe"
|
20
19
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
data/lib/enum_ext/version.rb
CHANGED
data/lib/enum_ext.rb
CHANGED
@@ -144,7 +144,7 @@ module EnumExt
|
|
144
144
|
# request1.payed? # >> true
|
145
145
|
# request2.payed? # >> true
|
146
146
|
# request1.updated_at # >> Time.now
|
147
|
-
#
|
147
|
+
# defined?(Request::MassAssignEnum) # >> true
|
148
148
|
#
|
149
149
|
# order.requests.already_payed.all?(&:already_payed?) # >> true
|
150
150
|
# order.requests.already_payed.delivered!
|
@@ -180,7 +180,7 @@ module EnumExt
|
|
180
180
|
enums_names.each do |enum_name|
|
181
181
|
enum_vals = self.send( enum_name.to_s.pluralize )
|
182
182
|
|
183
|
-
mass_ass_module = ( self
|
183
|
+
mass_ass_module = ( defined?(self::MassAssignEnum) && self::MassAssignEnum || Module.new )
|
184
184
|
|
185
185
|
mass_ass_module.instance_eval do
|
186
186
|
enum_vals.keys.each do |enum_el|
|
@@ -189,7 +189,7 @@ module EnumExt
|
|
189
189
|
end
|
190
190
|
end
|
191
191
|
end
|
192
|
-
self.const_set( :MassAssignEnum, mass_ass_module ) unless self
|
192
|
+
self.const_set( :MassAssignEnum, mass_ass_module ) unless defined?(self::MassAssignEnum)
|
193
193
|
|
194
194
|
self::ActiveRecord_Relation.include( self::MassAssignEnum ) if relation_options[:relation]
|
195
195
|
self::ActiveRecord_AssociationRelation.include( self::MassAssignEnum ) if relation_options[:association_relation]
|