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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 61001da4659fe8fed8fe0dd7eb7a00e0f053531e
4
- data.tar.gz: 98e2a5f2f72b48bbd96fbb0d6f75af6c9667809a
3
+ metadata.gz: af450b5d734ada4dd2dc96785aa307b71f772d47
4
+ data.tar.gz: 6c59231be591478bef3921a3a946eee9185eba5d
5
5
  SHA512:
6
- metadata.gz: 85932e315fea9508600ac8e9f68492c20e79cd10dce0716aa9ed48d8daf75cd94854b4eb5e8153fd0d94c95287eca8ec75d9e99099aa5f235691aad847b01ead
7
- data.tar.gz: cac5ad2ac88e7ac4f2db7a9b1b972c86d7fde70840c03fce938d2393da9b01f7f839a473132a8f760b39fa98fa22b2a9129c3fc4049eac498aa0cc76217b7ce7
6
+ metadata.gz: 3684b23a5b2f11e95dfc7a10de0cd0981c7915d837416dc21df5ef3ef91032b38f0e7b727f6d23ae43df833e1e768e6507364d76644ad1cca03c1e49837171db
7
+ data.tar.gz: 984b3b63965d5dc82086538a47fada270405a0b16f64b39592c614a0c40ee49bc52317a7c93c1edc4aa226903afdf15e5088031d7a411e2dd039f070c4a61217
data/README.md CHANGED
@@ -12,7 +12,7 @@ gem install report_logic
12
12
  Using Bundler:
13
13
 
14
14
  ```ruby
15
- gem 'report_logic', '~> 0.0.2'
15
+ gem 'report_logic', '~> 0.1.1'
16
16
  ```
17
17
 
18
18
  ## Usage
data/deploy ADDED
@@ -0,0 +1,3 @@
1
+ #!/bin/sh
2
+
3
+ gem build *.gemspec && gem push *.gem && rm *.gem
@@ -1,6 +1,6 @@
1
1
  module ReportLogic
2
2
  class Base
3
- extend Forwardable
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 main_session
16
- @main_session ||= Session.new(nil, self)
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
- 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)
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
@@ -1,7 +1,7 @@
1
1
  module ReportLogic
2
2
  module I18nSupport
3
3
  def i18n_decorate
4
- decorate_with I18nDecorator.new
4
+ decorators << I18nDecorator.new
5
5
  end
6
6
  end
7
7
  end
@@ -24,19 +24,16 @@ module ReportLogic
24
24
  field(nil, val, **options)
25
25
  end
26
26
 
27
- def process(collection = nil, &block)
27
+ def process(collection = nil)
28
28
  if collection.respond_to?(:each)
29
29
  collection.each do |record|
30
- begin
31
- @current_row = []
32
- instance_exec record, &block
33
- fields.push current_row
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
- instance_exec &block
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
@@ -1,5 +1,3 @@
1
- require 'forwardable'
2
-
3
1
  module ReportLogic
4
2
  autoload :Base , 'report_logic/base'
5
3
  autoload :Decorable , 'report_logic/decorable'
data/report_logic.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'report_logic'
3
- s.version = '0.1.0'
3
+ s.version = '0.1.1'
4
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. "\
@@ -13,7 +13,7 @@ class MyReport < ReportLogic::Base
13
13
  end
14
14
 
15
15
  session(:test_context) do
16
- report.context_value
16
+ context_value
17
17
  end
18
18
 
19
19
  session(:test_master_decorator) do
@@ -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.0
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
@@ -1,11 +0,0 @@
1
- class MyNestedSessions < ReportLogic::Base
2
- def build
3
- session :parent do
4
- value "I'm a father!"
5
-
6
- session :child, [1, 2] do
7
- value "bééééé"
8
- end
9
- end
10
- end
11
- end