Module: Enumish::ClassMethods
- Defined in:
- lib/enumish.rb
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_id, *args, &block) ⇒ Object
10
11
12
13
14
15
16
17
|
# File 'lib/enumish.rb', line 10
def method_missing(method_id, *args, &block)
if !method_id.to_s.match(/\?$/) && enum_ids.include?(method_id.to_s)
obj = self.where(enum_id => method_id.to_s).first
return obj if obj.present?
end
super method_id, *args, &block
end
|
Instance Method Details
#enum_id ⇒ Object
19
20
21
|
# File 'lib/enumish.rb', line 19
def enum_id
:short
end
|
#enum_ids ⇒ Object
29
30
31
32
|
# File 'lib/enumish.rb', line 29
def enum_ids
refresh_enum_ids! if @enum_ids.blank?
@enum_ids
end
|
#refresh_enum_ids! ⇒ Object
23
24
25
26
27
|
# File 'lib/enumish.rb', line 23
def refresh_enum_ids!
Mutex.new.synchronize do
@enum_ids = self.pluck(enum_id)
end
end
|