class Detroit::Custom
Custom
tool is used to create “quicky” services.
This is a useful alternative to writing a full-blown plugin when the need is simple.
Constants
- SPECIAL_OPTIONS
Plural alias for #group.
alias_accessor :groups, :group
Public Class Methods
new(options)
click to toggle source
Instantiate new custom plugin.
This works by interpreting the service configuration as a hash of stop names to ruby code.
Calls superclass method
# File lib/detroit-custom.rb, line 34 def initialize(options) super(options) @scripts = {} options.each do |stop, script| # skip specific names used for configuration next if SPECIAL_OPTIONS.include? stop # remaining options are names of group stops @scripts[stop.to_sym] = script end end
Public Instance Methods
assemble(stop, info={})
click to toggle source
# File lib/detroit-custom.rb, line 53 def assemble(stop, info={}) instance_eval(@scripts[stop]) end
assemble?(stop, info={})
click to toggle source
# File lib/detroit-custom.rb, line 48 def assemble?(stop, info={}) @scripts.key?(stop) end
Private Instance Methods
method_missing(s, *a, &b)
click to toggle source
Calls superclass method
# File lib/detroit-custom.rb, line 65 def method_missing(s, *a, &b) if s.to_s.end_with?('=') # stop = s.to_s.chomp('=') # if !SPECIAL_OPTIONS.include?(stop) # (class << self; self; end).module_eval %{ # def station_#{stop} # #{a.first} # end # } # end else if @context.respond_to?(s) @context.__send__(s,*a,&b) else super(s, *a, &b) end end end
respond_to_missing?(name, privy)
click to toggle source
RUBY 1.9
# File lib/detroit-custom.rb, line 91 def respond_to_missing?(name, privy) #return true if name.to_s.start_with?('station_') return true if name.to_s.end_with?('=') return true if @context.respond_to?(name) false end