class Stubby::Stub
Attributes
modes[RW]
path[RW]
target[RW]
Public Class Methods
new(path, target=nil)
click to toggle source
TODO: target is mode, rename
# File lib/stubby/stub.rb, line 6 def initialize(path, target=nil) self.path = path self.target = target end
Public Instance Methods
options()
click to toggle source
# File lib/stubby/stub.rb, line 35 def options @options ||= expand(modes[@environment] || {}) end
path=(v)
click to toggle source
# File lib/stubby/stub.rb, line 20 def path=(v) unless v and File.exists?(File.expand_path(v)) puts "'#{v}' not found. Use --config to specify a different config file" exit end @path = File.expand_path(v) end
search(trigger)
click to toggle source
# File lib/stubby/stub.rb, line 39 def search(trigger) options.each do |rule, instruction| if match=Regexp.new(rule, Regexp::EXTENDED | Regexp::IGNORECASE).match(trigger) instruction = instruction.dup match.to_a.each_with_index.map do |v, i| instruction.gsub!("$#{i}", v) end return instruction end end return nil end
target=(environment)
click to toggle source
# File lib/stubby/stub.rb, line 29 def target=(environment) @environment = environment @options = nil options end
Private Instance Methods
expand(options)
click to toggle source
# File lib/stubby/stub.rb, line 56 def expand(options) Stubby::Api.expand_rules(options) end