report_logic 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/deploy +3 -0
- data/lib/report_logic/base.rb +39 -9
- data/lib/report_logic/i18n_support.rb +1 -1
- data/lib/report_logic/session.rb +6 -26
- data/lib/report_logic.rb +0 -2
- data/report_logic.gemspec +1 -1
- data/spec/app/my_report.rb +1 -1
- data/spec/report_logic/base_spec.rb +0 -10
- metadata +2 -2
- data/spec/app/my_nested_sessions.rb +0 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: af450b5d734ada4dd2dc96785aa307b71f772d47
|
4
|
+
data.tar.gz: 6c59231be591478bef3921a3a946eee9185eba5d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3684b23a5b2f11e95dfc7a10de0cd0981c7915d837416dc21df5ef3ef91032b38f0e7b727f6d23ae43df833e1e768e6507364d76644ad1cca03c1e49837171db
|
7
|
+
data.tar.gz: 984b3b63965d5dc82086538a47fada270405a0b16f64b39592c614a0c40ee49bc52317a7c93c1edc4aa226903afdf15e5088031d7a411e2dd039f070c4a61217
|
data/README.md
CHANGED
data/deploy
ADDED
data/lib/report_logic/base.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module ReportLogic
|
2
2
|
class Base
|
3
|
-
|
3
|
+
include Decorable
|
4
4
|
|
5
5
|
attr_reader :collection
|
6
6
|
|
@@ -8,20 +8,37 @@ module ReportLogic
|
|
8
8
|
@collection = collection
|
9
9
|
end
|
10
10
|
|
11
|
+
def each(key)
|
12
|
+
return to_enum(__callee__, key) unless block_given?
|
13
|
+
ensure_built_and_decorated
|
14
|
+
sessions[key] and sessions[key].fields.each { |field| yield field }
|
15
|
+
end
|
16
|
+
|
17
|
+
def session(key, collection = nil, &block)
|
18
|
+
@current_session = sessions[key] ||= Session.new(key, self)
|
19
|
+
@current_session.process(collection, &block)
|
20
|
+
ensure
|
21
|
+
@current_session = nil
|
22
|
+
end
|
23
|
+
|
11
24
|
def count
|
12
25
|
@collection.size
|
13
26
|
end
|
14
27
|
|
15
|
-
def
|
16
|
-
@
|
28
|
+
def method_missing(method_name, *args, &block)
|
29
|
+
if @current_session && @current_session.public_methods.include?(method_name)
|
30
|
+
@current_session.public_send(method_name, *args, &block)
|
31
|
+
else
|
32
|
+
super
|
33
|
+
end
|
17
34
|
end
|
18
35
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
36
|
+
def decorate_with(*args)
|
37
|
+
if @current_session
|
38
|
+
@current_session.decorate_with(*args)
|
39
|
+
else
|
40
|
+
super
|
41
|
+
end
|
25
42
|
end
|
26
43
|
|
27
44
|
protected
|
@@ -36,5 +53,18 @@ module ReportLogic
|
|
36
53
|
def build
|
37
54
|
raise NotImplementedError
|
38
55
|
end
|
56
|
+
|
57
|
+
def decorate
|
58
|
+
sessions.values.each do |sess|
|
59
|
+
sess.decorate(@decorators)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
private
|
64
|
+
|
65
|
+
def sessions
|
66
|
+
@sessions ||= {}
|
67
|
+
end
|
68
|
+
|
39
69
|
end
|
40
70
|
end
|
data/lib/report_logic/session.rb
CHANGED
@@ -24,19 +24,16 @@ module ReportLogic
|
|
24
24
|
field(nil, val, **options)
|
25
25
|
end
|
26
26
|
|
27
|
-
def process(collection = nil
|
27
|
+
def process(collection = nil)
|
28
28
|
if collection.respond_to?(:each)
|
29
29
|
collection.each do |record|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
ensure
|
35
|
-
@current_row = nil
|
36
|
-
end
|
30
|
+
@current_row = []
|
31
|
+
yield record
|
32
|
+
fields.push current_row
|
33
|
+
@current_row = nil
|
37
34
|
end
|
38
35
|
else
|
39
|
-
|
36
|
+
yield
|
40
37
|
end
|
41
38
|
end
|
42
39
|
|
@@ -49,23 +46,6 @@ module ReportLogic
|
|
49
46
|
field_or_row.decorate(master_decorators + decorators)
|
50
47
|
end
|
51
48
|
end
|
52
|
-
children.each do |_, sess|
|
53
|
-
sess.decorate(decorators)
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
def each(key)
|
58
|
-
return to_enum(__callee__, key) unless block_given?
|
59
|
-
children[key] and children[key].fields.each { |field| yield field }
|
60
|
-
end
|
61
|
-
|
62
|
-
def session(key, collection = nil, &block)
|
63
|
-
sess = children[key] ||= Session.new(key, @report)
|
64
|
-
sess.process(collection, &block)
|
65
|
-
end
|
66
|
-
|
67
|
-
def children
|
68
|
-
@children ||= {}
|
69
49
|
end
|
70
50
|
end
|
71
51
|
end
|
data/lib/report_logic.rb
CHANGED
data/report_logic.gemspec
CHANGED
data/spec/app/my_report.rb
CHANGED
@@ -37,14 +37,4 @@ describe ReportLogic::Base do
|
|
37
37
|
expect(s1.first.value).to eq(3)
|
38
38
|
expect(s2.first.value).to eq(3)
|
39
39
|
end
|
40
|
-
|
41
|
-
context 'nesting sessions' do
|
42
|
-
it 'nests sessions' do
|
43
|
-
report = MyNestedSessions.new
|
44
|
-
report.build
|
45
|
-
expect(report.children.size).to eq(1)
|
46
|
-
expect(report.children.values.first.children.size).to eq(1)
|
47
|
-
expect(report.children.values.first.children.values.first.fields.size).to eq(2)
|
48
|
-
end
|
49
|
-
end
|
50
40
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: report_logic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Diego Aguir Selzlein
|
@@ -34,6 +34,7 @@ files:
|
|
34
34
|
- ".rspec"
|
35
35
|
- ".ruby-version"
|
36
36
|
- README.md
|
37
|
+
- deploy
|
37
38
|
- lib/report_logic.rb
|
38
39
|
- lib/report_logic/base.rb
|
39
40
|
- lib/report_logic/decorable.rb
|
@@ -47,7 +48,6 @@ files:
|
|
47
48
|
- script/console
|
48
49
|
- spec/app/my_decorator.rb
|
49
50
|
- spec/app/my_i18n_report.rb
|
50
|
-
- spec/app/my_nested_sessions.rb
|
51
51
|
- spec/app/my_report.rb
|
52
52
|
- spec/report_logic/base_spec.rb
|
53
53
|
- spec/report_logic/decorator_spec.rb
|