jeffp-enumerated_attribute 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +5 -0
- data/Rakefile +4 -4
- data/lib/enumerated_attribute.rb +53 -34
- data/spec/tractor.rb +1 -1
- metadata +4 -4
data/CHANGELOG.rdoc
CHANGED
data/Rakefile
CHANGED
@@ -5,10 +5,10 @@ require 'rake/contrib/sshpublisher'
|
|
5
5
|
|
6
6
|
spec = Gem::Specification.new do |s|
|
7
7
|
s.name = 'enumerated_attribute'
|
8
|
-
s.version = '0.1.
|
8
|
+
s.version = '0.1.5'
|
9
9
|
s.platform = Gem::Platform::RUBY
|
10
|
-
s.description = '
|
11
|
-
s.summary = '
|
10
|
+
s.description = 'An enumerated attribute accessor'
|
11
|
+
s.summary = 'Add enumerated attributes with initialization, dynamic predicate methods, more ...'
|
12
12
|
|
13
13
|
s.files = FileList['{examples,lib,tasks,spec}/**/*'] + %w(CHANGELOG.rdoc init.rb LICENSE Rakefile README.rdoc .gitignore) - FileList['**/*.log']
|
14
14
|
s.require_path = 'lib'
|
@@ -17,7 +17,7 @@ spec = Gem::Specification.new do |s|
|
|
17
17
|
|
18
18
|
s.author = 'Jeff Patmon'
|
19
19
|
s.email = 'jpatmon@yahoo.com'
|
20
|
-
s.homepage = 'http://
|
20
|
+
s.homepage = 'http://github.com/jeffp/enumerated_attribute/tree/master'
|
21
21
|
end
|
22
22
|
|
23
23
|
require 'spec/version'
|
data/lib/enumerated_attribute.rb
CHANGED
@@ -49,6 +49,7 @@ module EnumeratedAttribute
|
|
49
49
|
@integration_map[:aliasing].each do |p|
|
50
50
|
alias_method(p.first, p.last)
|
51
51
|
end
|
52
|
+
include(EnumeratedAttribute::Integrations::Default)
|
52
53
|
include(@integration_map[:module]) if @integration_map[:module]
|
53
54
|
|
54
55
|
def self.has_enumerated_attribute?(name)
|
@@ -183,51 +184,53 @@ module EnumeratedAttribute
|
|
183
184
|
class << self
|
184
185
|
def enumerated_attribute_initial_value_list; @enumerated_attribute_init; end
|
185
186
|
end
|
186
|
-
end
|
187
|
+
end
|
188
|
+
|
189
|
+
def self.define_enumerated_attribute_custom_method(symbol, attr_name, value, negated)
|
190
|
+
define_method symbol do
|
191
|
+
ival = read_enumerated_attribute(attr_name)
|
192
|
+
negated ? ival != value : ival == value
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
187
196
|
end
|
197
|
+
alias_method :enum_attr, :enumerated_attribute
|
188
198
|
|
189
|
-
|
190
|
-
alias :enum_attr :enumerated_attribute
|
191
|
-
|
199
|
+
=begin
|
192
200
|
def define_enumerated_attribute_custom_method(symbol, attr_name, value, negated)
|
193
201
|
define_method symbol do
|
194
202
|
ival = read_enumerated_attribute(attr_name)
|
195
203
|
negated ? ival != value : ival == value
|
196
204
|
end
|
197
205
|
end
|
198
|
-
|
199
|
-
private
|
206
|
+
=end
|
200
207
|
|
201
|
-
#these implementations are for basic ruby objects - integrations (see Integrations::ActiveRecord) may alter them
|
202
|
-
def define_enumerated_attribute_new_method
|
203
|
-
|
204
|
-
|
205
|
-
alias_method :new_without_enumerated_attribute, :new
|
206
|
-
def new(*args, &block)
|
207
|
-
result = new_without_enumerated_attribute(*args)
|
208
|
-
result.initialize_enumerated_attributes
|
209
|
-
yield result if block_given?
|
210
|
-
result
|
211
|
-
end
|
212
|
-
end
|
213
|
-
NEWMETH
|
214
|
-
end
|
215
|
-
|
216
|
-
def define_enumerated_attribute_writer_method name
|
217
|
-
name = name.to_s
|
218
|
-
class_eval <<-METHOD
|
219
|
-
def #{name}=(val); write_enumerated_attribute(:#{name}, val); end
|
220
|
-
METHOD
|
221
|
-
end
|
222
|
-
|
223
|
-
def define_enumerated_attribute_reader_method name
|
224
|
-
name = name.to_s
|
225
|
-
class_eval <<-METHOD
|
226
|
-
def #{name}; read_enumerated_attribute(:#{name}); end
|
227
|
-
METHOD
|
228
|
-
end
|
208
|
+
#these implementations are for basic ruby objects - integrations (see Integrations::ActiveRecord and Integrations::Object) may alter them
|
209
|
+
#def define_enumerated_attribute_new_method
|
210
|
+
#def define_enumerated_attribute_writer_method name
|
211
|
+
#def define_enumerated_attribute_reader_method name
|
229
212
|
|
230
213
|
module Integrations
|
214
|
+
module Default
|
215
|
+
def self.included(klass); klass.extend(ClassMethods); end
|
216
|
+
|
217
|
+
module ClassMethods
|
218
|
+
def define_enumerated_attribute_writer_method name
|
219
|
+
name = name.to_s
|
220
|
+
class_eval <<-METHOD
|
221
|
+
def #{name}=(val); write_enumerated_attribute(:#{name}, val); end
|
222
|
+
METHOD
|
223
|
+
end
|
224
|
+
|
225
|
+
def define_enumerated_attribute_reader_method name
|
226
|
+
name = name.to_s
|
227
|
+
class_eval <<-METHOD
|
228
|
+
def #{name}; read_enumerated_attribute(:#{name}); end
|
229
|
+
METHOD
|
230
|
+
end
|
231
|
+
end
|
232
|
+
end
|
233
|
+
|
231
234
|
module Object
|
232
235
|
def self.included(klass)
|
233
236
|
klass.extend(ClassMethods)
|
@@ -248,6 +251,22 @@ module EnumeratedAttribute
|
|
248
251
|
end
|
249
252
|
|
250
253
|
module ClassMethods
|
254
|
+
private
|
255
|
+
|
256
|
+
def define_enumerated_attribute_new_method
|
257
|
+
class_eval <<-NEWMETH
|
258
|
+
class << self
|
259
|
+
alias_method :new_without_enumerated_attribute, :new
|
260
|
+
def new(*args, &block)
|
261
|
+
result = new_without_enumerated_attribute(*args)
|
262
|
+
result.initialize_enumerated_attributes
|
263
|
+
yield result if block_given?
|
264
|
+
result
|
265
|
+
end
|
266
|
+
end
|
267
|
+
NEWMETH
|
268
|
+
end
|
269
|
+
|
251
270
|
end
|
252
271
|
|
253
272
|
end
|
data/spec/tractor.rb
CHANGED
@@ -25,7 +25,7 @@ class Tractor
|
|
25
25
|
plowing? { self.gear_is_in_first? && self.plow == :down }
|
26
26
|
end
|
27
27
|
|
28
|
-
enum_attr :lights, LIGHTS_ENUM_VALUES, :
|
28
|
+
enum_attr :lights, LIGHTS_ENUM_VALUES, :plural=>:lights_enums, :init=>:off, :decrementor=>:turn_lights_down, :incrementor=>:turn_lights_up do
|
29
29
|
lights_are_on? [:low, :high]
|
30
30
|
lights_are_not_on? :off
|
31
31
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jeffp-enumerated_attribute
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeff Patmon
|
@@ -13,7 +13,7 @@ date: 2009-07-14 00:00:00 -07:00
|
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
16
|
-
description:
|
16
|
+
description: An enumerated attribute accessor
|
17
17
|
email: jpatmon@yahoo.com
|
18
18
|
executables: []
|
19
19
|
|
@@ -41,7 +41,7 @@ files:
|
|
41
41
|
- README.rdoc
|
42
42
|
- .gitignore
|
43
43
|
has_rdoc: false
|
44
|
-
homepage: http://
|
44
|
+
homepage: http://github.com/jeffp/enumerated_attribute/tree/master
|
45
45
|
post_install_message:
|
46
46
|
rdoc_options: []
|
47
47
|
|
@@ -65,7 +65,7 @@ rubyforge_project:
|
|
65
65
|
rubygems_version: 1.2.0
|
66
66
|
signing_key:
|
67
67
|
specification_version: 3
|
68
|
-
summary:
|
68
|
+
summary: Add enumerated attributes with initialization, dynamic predicate methods, more ...
|
69
69
|
test_files:
|
70
70
|
- spec/new_and_method_missing_spec.rb
|
71
71
|
- spec/poro_spec.rb
|