Class: PennMARC::Parser
- Inherits:
-
Object
- Object
- PennMARC::Parser
- Defined in:
- lib/pennmarc/parser.rb
Overview
Access point for magic calls to helper methods
Instance Method Summary collapse
-
#method_missing(name, record, *opts) ⇒ Object
Call helper class methods, passing along additional arguments as needed, e.g.: #title_show -> PennMARC::Title.show #subject_facet -> PennMARC::Subject.facet.
-
#respond_to_missing?(name, include_private = false) ⇒ Boolean
Allow calls to ‘respond_to?` on parser instances to respond accurately by checking helper classes.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, record, *opts) ⇒ Object
Call helper class methods, passing along additional arguments as needed, e.g.: #title_show -> PennMARC::Title.show #subject_facet -> PennMARC::Subject.facet
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/pennmarc/parser.rb', line 32 def method_missing(name, record, *opts) helper, method_name = parse_call(name) raise NoMethodError unless helper && method_name helper_klass = "PennMARC::#{helper.titleize}".constantize if opts.any? helper_klass.public_send(method_name, record, **opts.first) else helper_klass.public_send(method_name, record) end end |
Instance Method Details
#respond_to_missing?(name, include_private = false) ⇒ Boolean
Allow calls to ‘respond_to?` on parser instances to respond accurately by checking helper classes
17 18 19 20 21 22 23 24 |
# File 'lib/pennmarc/parser.rb', line 17 def respond_to_missing?(name, include_private = false) helper, method_name = parse_call(name) begin "PennMARC::#{helper}".constantize.respond_to?(method_name) rescue NameError super # Helper is not defined, so check self end end |