dm-regex 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,4 @@
1
1
  rvm:
2
- - 1.8.7
3
2
  - 1.9.2
4
3
  - 1.9.3
5
4
  - rbx
data/README.md CHANGED
@@ -43,3 +43,48 @@ p ApacheLogEntry.match(
43
43
  )
44
44
  # => #<ApacheLogEntry @id=nil @h="87.18.183.252" @l="-" @u="-" @t=#<DateTime: 2008-08-13T00:50:49-07:00 ((2454692j,28249s,0n),-25200s,2299161j)> @r="GET /blog/index.xml HTTP/1.1" @s=302 @b=527 @referer="-" @user_agent="Feedreader 3.13 (Powered by Newsbrain)">
45
45
  ```
46
+
47
+ or using Regex compile options ...
48
+
49
+ ``` ruby
50
+ ApacheLogEntry.compile(%{
51
+ ^
52
+ \\g<h> # host
53
+ [ ]
54
+ \\g<l> # l
55
+ [ ]
56
+ \\g<u> # user
57
+ [ ]\\[
58
+ \\g<t> # timestamp
59
+ \\][ ]"
60
+ \\g<r> # request
61
+ "[ ]
62
+ \\g<s> # status
63
+ [ ]
64
+ \\g<b> # bytes
65
+ [ ]"
66
+ \\g<referer> # referer
67
+ "[ ]"
68
+ \\g<user_agent> # user agent
69
+ "$
70
+ },
71
+ Regexp::EXTENDED
72
+ )
73
+ ApacheLogEntry.match(
74
+ '87.18.183.252 - - [13/Aug/2008:00:50:49 -0700] "GET /blog/index.xml HTTP/1.1" 302 527 "-" "Feedreader 3.13 (Powered by Newsbrain)"'
75
+ ) do |o|
76
+ p o
77
+ end
78
+ # => #<ApacheLogEntry @id=nil @h="87.18.183.252" @l="-" @u="-" @t=#<DateTime: 2008-08-13T00:50:49-07:00 ((2454692j,28249s,0n),-25200s,2299161j)> @r="GET /blog/index.xml HTTP/1.1" @s=302 @b=527 @referer="-" @user_agent="Feedreader 3.13 (Powered by Newsbrain)">
79
+ ```
80
+
81
+ `.compile`
82
+ ---
83
+ * works the same as the built-in `Regexp.compile`
84
+ * uses named groups specified using `\g<name>` syntax to map groups to properties. (NB. make sure to use `\\g` when using double quoted strings)
85
+
86
+ `property opts`
87
+ ---
88
+
89
+ * `:pat` option specifies the pattern used to match the property. (NB. the default of `/.+?/` might be good enough in most cases)
90
+ * `:method` option takes a proc that is used to transform the matched value. (NB. DataMapper's built-in typescasting might be good enough in most cases)
@@ -15,6 +15,8 @@ Gem::Specification.new do |gem|
15
15
  gem.require_paths = [ "lib" ]
16
16
  gem.version = DataMapper::Regex::VERSION
17
17
 
18
+ gem.required_ruby_version = '>= 1.9.2'
19
+
18
20
  gem.add_runtime_dependency('dm-core', '~> 1.0')
19
21
  gem.add_runtime_dependency('dm-migrations', '~> 1.0')
20
22
  gem.add_runtime_dependency('dm-sqlite-adapter', '~> 1.0')
@@ -15,7 +15,9 @@ module DataMapper
15
15
  end
16
16
 
17
17
  def match(buf, parent=self)
18
- pat.match(buf) { |m| parent.first_or_new(attrs_from_match(m)) }
18
+ pat.match(buf) { |m| parent.first_or_new(attrs_from_match(m)) }.tap { |obj|
19
+ yield obj if block_given?
20
+ }
19
21
  end
20
22
 
21
23
  def property(name, type, opts={}, &block)
@@ -1,5 +1,5 @@
1
1
  module DataMapper
2
2
  module Regex
3
- VERSION = '0.0.1'
3
+ VERSION = '0.0.2'
4
4
  end
5
5
  end
@@ -26,10 +26,6 @@ describe DataMapper::Regex do
26
26
  describe '.match' do
27
27
  subject { ApacheLogEntry.match(line) }
28
28
 
29
- before :all do
30
-
31
- end
32
-
33
29
  let(:line) {
34
30
  '87.18.183.252 - - [13/Aug/2008:00:50:49 -0700] "GET /blog/index.xml HTTP/1.1" 302 527 "-" "Feedreader 3.13 (Powered by Newsbrain)"'
35
31
  }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dm-regex
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -120,10 +120,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
120
120
  requirements:
121
121
  - - ! '>='
122
122
  - !ruby/object:Gem::Version
123
- version: '0'
124
- segments:
125
- - 0
126
- hash: -1581250388491881790
123
+ version: 1.9.2
127
124
  required_rubygems_version: !ruby/object:Gem::Requirement
128
125
  none: false
129
126
  requirements:
@@ -132,7 +129,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
132
129
  version: '0'
133
130
  segments:
134
131
  - 0
135
- hash: -1581250388491881790
132
+ hash: 1459867127956847609
136
133
  requirements: []
137
134
  rubyforge_project:
138
135
  rubygems_version: 1.8.24