epo 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -23,7 +23,6 @@ spec = Gem::Specification.new do |s|
23
23
  'lib/epo.rb',
24
24
  'lib/epo/core/db.rb',
25
25
  'lib/epo/core/observer.rb',
26
- 'lib/epo/core/dispatch_observations.rb',
27
26
  ]
28
27
 
29
28
  s.require_path = 'lib'
@@ -32,7 +31,7 @@ spec = Gem::Specification.new do |s|
32
31
  s.has_rdoc = true
33
32
 
34
33
  s.add_dependency('derailleur', '>= 0.0.6')
35
- s.add_dependency('welo', '>= 0.1.0')
34
+ s.add_dependency('welo', '>= 0.1.1')
36
35
  end
37
36
 
38
37
  Rake::GemPackageTask.new(spec) do |pkg|
data/lib/epo.rb CHANGED
@@ -1,6 +1,6 @@
1
1
 
2
2
  module EPO
3
- VERSION = "0.0.2"
3
+ VERSION = "0.0.3"
4
4
  AUTHORS = ["crapooze"]
5
5
  WEBSITE = "https://github.com/crapooze/epo"
6
6
  LICENCE = "MIT"
data/lib/epo/core/db.rb CHANGED
@@ -185,7 +185,7 @@ module EPO
185
185
  end
186
186
  end
187
187
  else
188
- Enumerator.new(self, root, resources, persps, exts)
188
+ Enumerator.new(self, :batch_save_actions, root, resources, persps, exts)
189
189
  end
190
190
  end
191
191
 
@@ -2,22 +2,25 @@
2
2
  require 'welo'
3
3
  require 'find'
4
4
  require 'epo/core/db'
5
- require 'epo/core/dispatch_observations'
6
5
 
7
6
  module EPO
8
7
  # An Observer is a object able to look at the filesystem and
9
8
  # observe resources in it.
10
9
  class Observer < Welo::Observer
11
- include DispatchObservations
10
+ alias :on :register
11
+
12
12
  # in EPO, the source of an observation is:
13
13
  # - a db object able to make a ruby object from a file path
14
14
  # - a file path
15
15
  Source = Struct.new(:db, :path) do
16
16
  def observe
17
- db.read_file(path)
17
+ yield db.read_file(path)
18
18
  end
19
19
  end
20
20
 
21
+ # The list of models understood by this observer
22
+ attr_reader :models
23
+
21
24
  # The DB able to tell if a path is understandable or not
22
25
  attr_accessor :db
23
26
 
@@ -35,25 +38,38 @@ module EPO
35
38
  # Creates a new observer for given models.
36
39
  # Will instanciate a new DB.
37
40
  def initialize(models=[])
38
- super(models)
41
+ super()
39
42
  @db = DB.new(models)
40
43
  @structures = {}
41
44
  register(:observation) do |o|
42
- dispatch(o)
45
+ event(o.class.resource, o)
43
46
  end
44
47
  end
45
48
 
49
+ # Returns the node for a db path, or nil if doesnt exist
46
50
  def get_node_for_path(path, root=nil)
47
- path = path.sub(root,'') if root
51
+ case root
52
+ when Regexp
53
+ path = path.sub(root,'')
54
+ when String
55
+ re = %r{^#{root}}
56
+ path = path.sub(re,'')
57
+ when nil
58
+ #ok
59
+ else
60
+ raise ArgumentError, "can only understand string or regexps as roots"
61
+ end
48
62
  db.get_route_silent(path)
49
63
  end
50
64
 
65
+ # Reads the file to path as a resource dumped EPO-style
51
66
  def read_path_as_resource(path, model)
52
67
  persp_str = db.persp_and_ext_for_basename(path).first
53
68
  persp = model.perspectives.keys.find{|k| k.to_s == persp_str}
54
69
  observe_source(Source.new(db, path), structure(model, persp))
55
70
  end
56
71
 
72
+ # Handy-cache for mapping (model, persp) pairs to Welo::ObservationStruct
57
73
  def structure(model, persp)
58
74
  pair = [model, persp]
59
75
  @structures[pair] ||= Welo::ObservationStruct.new_for_resource_in_perspective(model, persp)
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: epo
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 25
4
5
  prerelease: false
5
6
  segments:
6
7
  - 0
7
8
  - 0
8
- - 2
9
- version: 0.0.2
9
+ - 3
10
+ version: 0.0.3
10
11
  platform: ruby
11
12
  authors:
12
13
  - crapooze
@@ -14,7 +15,7 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2011-03-27 00:00:00 -04:00
18
+ date: 2011-04-11 00:00:00 -04:00
18
19
  default_executable:
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
@@ -25,6 +26,7 @@ dependencies:
25
26
  requirements:
26
27
  - - ">="
27
28
  - !ruby/object:Gem::Version
29
+ hash: 19
28
30
  segments:
29
31
  - 0
30
32
  - 0
@@ -40,11 +42,12 @@ dependencies:
40
42
  requirements:
41
43
  - - ">="
42
44
  - !ruby/object:Gem::Version
45
+ hash: 25
43
46
  segments:
44
47
  - 0
45
48
  - 1
46
- - 0
47
- version: 0.1.0
49
+ - 1
50
+ version: 0.1.1
48
51
  type: :runtime
49
52
  version_requirements: *id002
50
53
  description:
@@ -62,7 +65,6 @@ files:
62
65
  - lib/epo.rb
63
66
  - lib/epo/core/db.rb
64
67
  - lib/epo/core/observer.rb
65
- - lib/epo/core/dispatch_observations.rb
66
68
  has_rdoc: true
67
69
  homepage: https://github.com/crapooze/epo
68
70
  licenses: []
@@ -77,6 +79,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
77
79
  requirements:
78
80
  - - ">="
79
81
  - !ruby/object:Gem::Version
82
+ hash: 3
80
83
  segments:
81
84
  - 0
82
85
  version: "0"
@@ -85,6 +88,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
85
88
  requirements:
86
89
  - - ">="
87
90
  - !ruby/object:Gem::Version
91
+ hash: 3
88
92
  segments:
89
93
  - 0
90
94
  version: "0"
@@ -1,21 +0,0 @@
1
-
2
- module EPO
3
- module DispatchObservations
4
- # Register an event when an observation of a resource
5
- # matching a given model is made
6
- def on(model,&blk)
7
- register(model,&blk)
8
- end
9
-
10
- private
11
-
12
- # Call each blocks for an observation registering from the
13
- # observation's resource model
14
- def dispatch(observation)
15
- blks = registrations[observation.class.resource] || []
16
- blks.each do |blk|
17
- blk.call(observation)
18
- end
19
- end
20
- end
21
- end