enum_ext 0.2.0 → 0.2.1

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: ed6a02d91d85ab0c0580df99fc4747513053eef1
4
- data.tar.gz: d66d1b253f9bd512c1eed331b980591b4c774222
3
+ metadata.gz: 4e95f6a4c82487df31be4eb7e31a4f310292c590
4
+ data.tar.gz: 367ea13f066e7a7fe7b00ad790d36983a5b6e000
5
5
  SHA512:
6
- metadata.gz: 14ac092e452730ef84fcc313877de7fb83254c35ca009ba032e9a1794bb3e391141b4f553c0aa7884e2b69d332feb1c94f06e2527a87ca434657562ec0a4de4c
7
- data.tar.gz: 171c5a7736a49e9c592c3d92005b93c312610698cc0c7e7d60aed13e5a712eed9728629473aa41f1b1f1d4dd40fd72c4a84227561217051620dd463f64ae1055
6
+ metadata.gz: 8032fae12c639e80edfdf9940da399660cb3f9d0c64f096d8a8ae33d8139eb250071bbc8dc4e97ebfdfc1a041196b8fcd13df3fde45f9867d9932eaecc53ab20
7
+ data.tar.gz: d82b610d27f075c96d94e3457338ba394710e94296ac5e31c947423eb00accfc1a02f6e0123948cf782d8250d24b07d42ba9679817b5a5de147494e53fa6539a
@@ -1,3 +1,3 @@
1
1
  module EnumExt
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
data/lib/enum_ext.rb CHANGED
@@ -61,12 +61,14 @@ module EnumExt
61
61
  # outside_wharehouse: ( delivery_set_statuses - in_warehouse_statuses )... any other array operations like &, + and so can be used
62
62
  # }
63
63
  def ext_enum_sets( enum_name, options )
64
+ enum_plural = enum_name.to_s.pluralize
65
+
64
66
  self.instance_eval do
65
67
  options.each do |set_name, enum_vals|
66
- scope set_name, -> { where( enum_name => self.send( enum_name.to_s.pluralize ).slice( *enum_vals.map(&:to_s) ).values ) }
68
+ scope set_name, -> { where( enum_name => self.send( enum_plural ).slice( *enum_vals.map(&:to_s) ).values ) }
67
69
 
68
70
 
69
- define_singleton_method( "#{set_name}_#{enum_name.to_s.pluralize}" ) do
71
+ define_singleton_method( "#{set_name}_#{enum_plural}" ) do
70
72
  enum_vals
71
73
  end
72
74
 
@@ -76,33 +78,33 @@ module EnumExt
76
78
  end
77
79
 
78
80
  # t_set_enums
79
- define_singleton_method( "t_#{set_name}_#{enum_name.to_s.pluralize}" ) do
80
- send( "t_#{enum_name.to_s.pluralize}" ).slice( *self.send("#{set_name}_#{enum_name.to_s.pluralize}") )
81
+ define_singleton_method( "t_#{set_name}_#{enum_plural}" ) do
82
+ send( "t_#{enum_plural}" ).slice( *self.send("#{set_name}_#{enum_plural}") )
81
83
  end
82
84
 
83
85
  # t_set_enums_options
84
- define_singleton_method( "t_#{set_name}_#{enum_name.to_s.pluralize}_options" ) do
85
- send( "t_#{set_name}_#{enum_name.to_s.pluralize}" ).invert.to_a.map do | key_val |
86
+ define_singleton_method( "t_#{set_name}_#{enum_plural}_options" ) do
87
+ send( "t_#{set_name}_#{enum_plural}" ).invert.to_a.map do | key_val |
86
88
  key_val[0] = key_val[0].call if key_val[0].respond_to?(:call) && key_val[0].try(:arity) < 1
87
89
  key_val
88
90
  end
89
91
  end
90
92
 
91
93
  # set_enums_i
92
- define_singleton_method( "#{set_name}_#{enum_name.to_s.pluralize}_i" ) do
93
- self.send( "#{enum_name.to_s.pluralize}" ).slice( *self.send("#{set_name}_#{enum_name.to_s.pluralize}") ).values
94
+ define_singleton_method( "#{set_name}_#{enum_plural}_i" ) do
95
+ self.send( "#{enum_plural}" ).slice( *self.send("#{set_name}_#{enum_plural}") ).values
94
96
  end
95
97
 
96
98
  end
97
99
 
98
- scope "with_#{enum_name.to_s.pluralize}", -> (sets_arr) {
99
- where( enum_name => self.send( enum_name.to_s.pluralize ).slice(
100
- *sets_arr.map{|set_name| self.try( "#{set_name}_#{enum_name.to_s.pluralize}" ) || set_name }.flatten.uniq.map(&:to_s) ).values )
101
- } unless respond_to?("with_#{enum_name.to_s.pluralize}")
100
+ scope "with_#{enum_plural}", -> (sets_arr) {
101
+ where( enum_name => self.send( enum_plural ).slice(
102
+ *sets_arr.map{|set_name| self.try( "#{set_name}_#{enum_plural}" ) || set_name }.flatten.uniq.map(&:to_s) ).values )
103
+ } unless respond_to?("with_#{enum_plural}")
102
104
 
103
- scope "without_#{enum_name.to_s.pluralize}", -> (sets_arr) {
104
- where.not( id: self.send("with_#{enum_name.to_s.pluralize}", sets_arr) )
105
- } unless respond_to?("without_#{enum_name.to_s.pluralize}")
105
+ scope "without_#{enum_plural}", -> (sets_arr) {
106
+ where.not( id: self.send("with_#{enum_plural}", sets_arr) )
107
+ } unless respond_to?("without_#{enum_plural}")
106
108
  end
107
109
  end
108
110
 
@@ -230,7 +232,7 @@ module EnumExt
230
232
  define_singleton_method( "t_#{enum_pural}" ) do
231
233
  # if localization is abscent than block must be given
232
234
  localizations.try(:with_indifferent_access) || localizations ||
233
- send(enum_pural).keys.map {|en| [en, self.new( {enum_name => en} ).send("t_#{enum_name}")] }.to_h
235
+ send(enum_pural).keys.map {|en| [en, self.new( {enum_name => en} ).send("t_#{enum_name}")] }.to_h.with_indifferent_access
234
236
  end
235
237
 
236
238
  #t_enums_options
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: enum_ext
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - alekseyl