Module: DataMapper::Regex::ClassMethods

Defined in:
lib/dm-regex/regex.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#patObject (readonly)

Returns the value of attribute pat.



10
11
12
# File 'lib/dm-regex/regex.rb', line 10

def pat
  @pat
end

Instance Method Details

#compile(pattern, options = 0) ⇒ Object



12
13
14
15
# File 'lib/dm-regex/regex.rb', line 12

def compile(pattern, options=0)
  @group_names = pattern.scan(/\\g<(\w+)>/).flatten.map(&:to_sym)
  @pat = ::Regexp.compile("#{groups}#{pattern}", options)
end

#match(buf, parent = self) ⇒ Object



17
18
19
20
21
# File 'lib/dm-regex/regex.rb', line 17

def match(buf, parent=self)
  pat.match(buf) { |m| parent.first_or_new(attrs_from_match(m)) }.tap { |obj|
    yield obj if block_given?
  }
end

#property(name, type, opts = {}, &block) ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'lib/dm-regex/regex.rb', line 23

def property(name, type, opts={}, &block)
  if group_pat = opts.delete(:pat)
    map_pat[name] = group_pat
  end
  if group_method = opts.delete(:method)
    map_method[name] = group_method
  end
  super
end