Class: EacRubyUtils::ObjectsTable
- Inherits:
-
Object
- Object
- EacRubyUtils::ObjectsTable
show all
- Defined in:
- lib/eac_ruby_utils/objects_table.rb
Defined Under Namespace
Classes: BY_PARSER_PARSED_STRUCT
Constant Summary
collapse
- BY_PARSER =
::EacRubyUtils::RegexpParser.new(/\Aby_([^!\?]+)(!)?\z/) do |m|
BY_PARSER_PARSED_STRUCT.new(m[1], "by_attribute#{'!' if m[2].present?}")
end
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *arguments, &block) ⇒ Object
33
34
35
36
37
38
39
|
# File 'lib/eac_ruby_utils/objects_table.rb', line 33
def method_missing(method_name, *arguments, &block)
if (parsed = BY_PARSER.parse(method_name))
return send(parsed.method_name, parsed.attribute, *arguments, &block)
end
super
end
|
Instance Method Details
#by_attribute(name, value) ⇒ Object?
17
18
19
|
# File 'lib/eac_ruby_utils/objects_table.rb', line 17
def by_attribute(name, value)
objects.find { |e| e.send(name) == value }
end
|
#by_attribute!(name, value) ⇒ Object
24
25
26
27
|
# File 'lib/eac_ruby_utils/objects_table.rb', line 24
def by_attribute!(name, value)
by_attribute(name, value) ||
raise(::ArgumentError, "No item found with attribute #{name}=#{value}")
end
|
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
29
30
31
|
# File 'lib/eac_ruby_utils/objects_table.rb', line 29
def respond_to_missing?(method_name, include_private = false)
super || BY_PARSER.parse?(method_name)
end
|