Class: Luruju::JudeApi::JudeBase
- Inherits:
-
Object
- Object
- Luruju::JudeApi::JudeBase
show all
- Includes:
- DynamicMethod
- Defined in:
- lib/luruju/add_useful_method.rb
Instance Method Summary
collapse
#method_missing
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class Luruju::DynamicMethod
Instance Method Details
#dyna_01_select_XXXs_by_YYY(method, *args) ⇒ Object
10
11
12
13
14
15
16
|
# File 'lib/luruju/add_useful_method.rb', line 10
def dyna_01_select_XXXs_by_YYY(method, *args)
raise IsNotMyRole unless /^(find_all|select)_(.+?)_by_(.+?)$/ =~ method.to_s
a_getter, attr, param = $2, $3, args[0]
raise IsNotMyRole unless self.class.method_defined?(a_getter)
ope = param.instance_of?(Regexp) ? "=~" : "=="
instance_eval("#{a_getter}.select{|i|i.#{attr} #{ope} param}");
end
|
#dyna_02_find_XXX_by_YYY(method, *args) ⇒ Object
18
19
20
21
22
23
24
|
# File 'lib/luruju/add_useful_method.rb', line 18
def dyna_02_find_XXX_by_YYY(method, *args)
raise IsNotMyRole unless /^find_(.+?)_by_(.+?)$/ =~ method.to_s
clazz, attr, param = $1, $2, args[0]
a_getter = Inflector.pluralize(clazz)
ope = param.instance_of?(Regexp) ? "=~" : "=="
instance_eval("#{a_getter}.find{|i|i.#{attr} #{ope} param}");
end
|
#dyna_children_access(method, *args) ⇒ Object
26
27
28
29
30
31
|
# File 'lib/luruju/add_useful_method.rb', line 26
def dyna_children_access(method, *args)
raise IsNotMyRole unless self.class.method_defined?(:owned_elements)
api_name = "Jude" + Inflector.classify(method.to_s)
raise IsNotMyRole unless JudeApi.constants.include?(api_name)
owned_elements.select{|p| p.instance_of?(JudeApi.module_eval(api_name))}
end
|