Module: Ygg
- Defined in:
- lib/ygg.rb,
lib/ygg/record.rb,
lib/ygg/session.rb,
lib/ygg/version.rb,
lib/ygg/bck/link.rb,
lib/ygg/bck/model.rb,
lib/ygg/bck/branch.rb,
lib/ygg/databundle.rb,
lib/ygg/exceptions.rb,
lib/ygg/bck/exceptions.rb
Defined Under Namespace
Modules: Record
Classes: Branch, DataBundle, InvalidInitializor, InvalidResourceException, Link, Model, NoInteractionDoneException, OutOfBlockException, Session, UnavailableResourceException
Constant Summary
collapse
- VERSION =
"1.0.6"
Class Method Summary
collapse
Class Method Details
.add(*resources) ⇒ Object
54
55
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/ygg.rb', line 54
def self.add(*resources)
raise ArgumentError if resources.empty?
begin
event = events.last
resources.each do |resource|
event.records << resource
end
rescue NoInteractionDoneException => e
raise UnavailableResourceException, "No resource was loaded, impossible to add the object"
end
end
|
.base_dir ⇒ Object
75
76
77
|
# File 'lib/ygg.rb', line 75
def self.base_dir
@@base_dir
end
|
.base_dir=(dir) ⇒ Object
71
72
73
|
# File 'lib/ygg.rb', line 71
def self.base_dir=(dir)
@@base_dir = dir
end
|
.events ⇒ Object
79
80
81
82
|
# File 'lib/ygg.rb', line 79
def self.events
raise NoInteractionDoneException, "No events to load in the log." if @@sessions.empty?
@@sessions
end
|
.path_to(source) ⇒ Object
20
21
22
23
24
25
26
|
# File 'lib/ygg.rb', line 20
def self.path_to( source )
if source.is_a? Symbol
return "#{@@base_dir}/#{source}.ygg"
else
return source
end
end
|
.records ⇒ Object
67
68
69
|
# File 'lib/ygg.rb', line 67
def self.records
events.last.records
end
|
.reset ⇒ Object
13
14
15
16
|
# File 'lib/ygg.rb', line 13
def self.reset
@@base_dir = "."
@@sessions = []
end
|
.resource(*args) ⇒ Object
84
85
86
87
88
89
90
91
92
93
94
|
# File 'lib/ygg.rb', line 84
def self.resource(*args)
if args.empty?
raise OutOfBlockException, "The resource is not available outside an ygg block." unless @@within_block
events.last
else
case args[0]
when :path
events.last.source
end
end
end
|
.transaction(source, &block) ⇒ Object
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/ygg.rb', line 28
def self.transaction( source, &block )
if not block and not File.exist?(path_to(source))
raise UnavailableResourceException,
"No resource was found in #{path_to(source)}"
end
@@sessions << Session.new(path_to(source))
if block
@@within_block = true
yield block
@@within_block = nil
@@sessions.last.shutdown
end
return @@sessions.last.records
end
|
.ygg(*args, &block) ⇒ Object
45
46
47
48
49
50
51
52
|
# File 'lib/ygg.rb', line 45
def self.ygg(*args, &block)
return Ygg if args.empty?
self.base_dir = args.shift if args.length > 1
source = args.shift
transaction(source, &block)
end
|