report_logic 0.0.2 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/lib/report_logic.rb +2 -0
- data/lib/report_logic/base.rb +9 -38
- data/lib/report_logic/field.rb +7 -6
- data/lib/report_logic/i18n_support.rb +1 -1
- data/lib/report_logic/session.rb +26 -6
- data/report_logic.gemspec +2 -2
- data/script/console +9 -0
- data/spec/app/my_nested_sessions.rb +11 -0
- data/spec/app/my_report.rb +1 -1
- data/spec/report_logic/base_spec.rb +10 -0
- data/spec/report_logic/field_spec.rb +11 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 61001da4659fe8fed8fe0dd7eb7a00e0f053531e
|
4
|
+
data.tar.gz: 98e2a5f2f72b48bbd96fbb0d6f75af6c9667809a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 85932e315fea9508600ac8e9f68492c20e79cd10dce0716aa9ed48d8daf75cd94854b4eb5e8153fd0d94c95287eca8ec75d9e99099aa5f235691aad847b01ead
|
7
|
+
data.tar.gz: cac5ad2ac88e7ac4f2db7a9b1b972c86d7fde70840c03fce938d2393da9b01f7f839a473132a8f760b39fa98fa22b2a9129c3fc4049eac498aa0cc76217b7ce7
|
data/README.md
CHANGED
@@ -68,8 +68,8 @@ report.each(:row) do |row|
|
|
68
68
|
print field.value
|
69
69
|
print ' | '
|
70
70
|
end
|
71
|
+
puts
|
71
72
|
end
|
72
|
-
puts
|
73
73
|
```
|
74
74
|
|
75
75
|
This output sucks, but it shows how simple it is to read a report
|
@@ -125,7 +125,7 @@ end
|
|
125
125
|
You can apply a decorator to a specific field. To do so, you need to:
|
126
126
|
|
127
127
|
```ruby
|
128
|
-
field 'Name', record.name, decorate_with:
|
128
|
+
field 'Name', record.name, decorate_with: SpecificDecorator.new
|
129
129
|
```
|
130
130
|
|
131
131
|
## I18n Support
|
data/lib/report_logic.rb
CHANGED
data/lib/report_logic/base.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module ReportLogic
|
2
2
|
class Base
|
3
|
-
|
3
|
+
extend Forwardable
|
4
4
|
|
5
5
|
attr_reader :collection
|
6
6
|
|
@@ -8,37 +8,20 @@ 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
|
-
|
24
11
|
def count
|
25
12
|
@collection.size
|
26
13
|
end
|
27
14
|
|
28
|
-
def
|
29
|
-
|
30
|
-
@current_session.public_send(method_name, *args, &block)
|
31
|
-
else
|
32
|
-
super
|
33
|
-
end
|
15
|
+
def main_session
|
16
|
+
@main_session ||= Session.new(nil, self)
|
34
17
|
end
|
35
18
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
19
|
+
def_delegators :main_session, :session, :decorate_with, :field, :value,
|
20
|
+
:decorate, :children
|
21
|
+
|
22
|
+
def each(*args, &block)
|
23
|
+
ensure_built_and_decorated
|
24
|
+
main_session.each(*args, &block)
|
42
25
|
end
|
43
26
|
|
44
27
|
protected
|
@@ -53,17 +36,5 @@ module ReportLogic
|
|
53
36
|
def build
|
54
37
|
raise NotImplementedError
|
55
38
|
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
|
end
|
69
40
|
end
|
data/lib/report_logic/field.rb
CHANGED
@@ -2,13 +2,14 @@ module ReportLogic
|
|
2
2
|
class Field
|
3
3
|
include Decorable
|
4
4
|
|
5
|
-
attr_accessor :key, :value, :type, :name
|
5
|
+
attr_accessor :key, :value, :type, :name, :config
|
6
6
|
|
7
|
-
def initialize(name, value=nil, type: nil, key: nil, decorate_with: nil)
|
8
|
-
@name
|
9
|
-
@value
|
10
|
-
@type
|
11
|
-
@
|
7
|
+
def initialize(name, value=nil, type: nil, key: nil, decorate_with: nil, **config)
|
8
|
+
@name = name
|
9
|
+
@value = value
|
10
|
+
@type = type
|
11
|
+
@config = config
|
12
|
+
@key = key || (name.is_a?(Symbol) ? name : nil)
|
12
13
|
self.decorate_with(decorate_with)
|
13
14
|
end
|
14
15
|
|
data/lib/report_logic/session.rb
CHANGED
@@ -24,16 +24,19 @@ module ReportLogic
|
|
24
24
|
field(nil, val, **options)
|
25
25
|
end
|
26
26
|
|
27
|
-
def process(collection = nil)
|
27
|
+
def process(collection = nil, &block)
|
28
28
|
if collection.respond_to?(:each)
|
29
29
|
collection.each do |record|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
30
|
+
begin
|
31
|
+
@current_row = []
|
32
|
+
instance_exec record, &block
|
33
|
+
fields.push current_row
|
34
|
+
ensure
|
35
|
+
@current_row = nil
|
36
|
+
end
|
34
37
|
end
|
35
38
|
else
|
36
|
-
|
39
|
+
instance_exec &block
|
37
40
|
end
|
38
41
|
end
|
39
42
|
|
@@ -46,6 +49,23 @@ module ReportLogic
|
|
46
49
|
field_or_row.decorate(master_decorators + decorators)
|
47
50
|
end
|
48
51
|
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 ||= {}
|
49
69
|
end
|
50
70
|
end
|
51
71
|
end
|
data/report_logic.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'report_logic'
|
3
|
-
s.version = '0.0
|
4
|
-
s.date = '2014-
|
3
|
+
s.version = '0.1.0'
|
4
|
+
s.date = '2014-11-18'
|
5
5
|
s.summary = "Generating report logic."
|
6
6
|
s.description = "This gem provides an easy way to generate reports' logic. "\
|
7
7
|
"Using this, you can so export this report to any format you want."
|
data/script/console
ADDED
data/spec/app/my_report.rb
CHANGED
@@ -37,4 +37,14 @@ 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
|
40
50
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: report_logic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Diego Aguir Selzlein
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-11-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: i18n
|
@@ -44,11 +44,14 @@ files:
|
|
44
44
|
- lib/report_logic/i18n_support.rb
|
45
45
|
- lib/report_logic/session.rb
|
46
46
|
- report_logic.gemspec
|
47
|
+
- script/console
|
47
48
|
- spec/app/my_decorator.rb
|
48
49
|
- spec/app/my_i18n_report.rb
|
50
|
+
- spec/app/my_nested_sessions.rb
|
49
51
|
- spec/app/my_report.rb
|
50
52
|
- spec/report_logic/base_spec.rb
|
51
53
|
- spec/report_logic/decorator_spec.rb
|
54
|
+
- spec/report_logic/field_spec.rb
|
52
55
|
- spec/report_logic/i18n_support_spec.rb
|
53
56
|
- spec/report_logic/session_spec.rb
|
54
57
|
- spec/spec_helper.rb
|