ruby_reportable 0.1.3.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ruby_reportable (0.1.2)
4
+ ruby_reportable (0.1.3)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
data/README.md CHANGED
@@ -42,6 +42,11 @@ Install as a gem or use as part of your Gemfile
42
42
 
43
43
  $ [sudo] gem install ruby_reportable
44
44
 
45
+ ## Configuration
45
46
 
47
+ ### Version 0.2.X
46
48
 
49
+ There is a change in what is returned when a report is validated (object.report.valid?). In 0.1.X true/false is returned but in 0.2.X a hash is returned containing whether the report is valid (status) and an array of errors if any (errors).
50
+
51
+ {:status => true/false, :errors => array }
47
52
 
@@ -1,8 +1,19 @@
1
1
  class ObjectSpaceReport
2
2
  include RubyReportable
3
3
 
4
- name 'Object Space By Class'
4
+ #
5
+ # Name the report
6
+ #
7
+ report 'Object Space By Class'
5
8
 
9
+ #
10
+ # Give the report a category for organization
11
+ #
12
+ category 'Object Reports'
13
+
14
+ #
15
+ # Define the data source
16
+ #
6
17
  source do
7
18
  as :object
8
19
 
@@ -11,6 +22,38 @@ class ObjectSpaceReport
11
22
  end
12
23
  end
13
24
 
25
+ #
26
+ # Perform a final manipulation to the returned records like making sure all are unique
27
+ #
28
+ finalize
29
+ source.all.uniq
30
+ end
31
+
32
+ #
33
+ # Define output fields
34
+ #
14
35
  output('Class') { object.first.to_s }
15
36
  output('Total') { object.last.size }
37
+
38
+ #
39
+ # Define a filter to help select which records to find
40
+ #
41
+ filter('Just These Objects') do
42
+ priority 0
43
+ key :just_these_objects
44
+ require # Require an input for this filter
45
+
46
+ input(:value) {}
47
+
48
+ valid? do
49
+ # Check to see if an input is present
50
+ validity = !input.blank?
51
+ !! validity
52
+ end
53
+
54
+ logic do
55
+ # Perform some logic using the input
56
+ source.where(["object = #{input}"])
57
+ end
58
+ end
16
59
  end
@@ -170,6 +170,7 @@ module RubyReportable
170
170
 
171
171
  def valid?(options = {})
172
172
  options = {:input => {}}.merge(options)
173
+ errors = []
173
174
 
174
175
  # initial sandbox
175
176
  sandbox = _source(options)
@@ -178,6 +179,7 @@ module RubyReportable
178
179
  sandbox[:inputs] = options[:input]
179
180
 
180
181
  validity = @filters.map do |filter_name, filter|
182
+
181
183
  # find input for given filter
182
184
  sandbox[:input] = options[:input][filter[:key]] if options[:input].is_a?(Hash)
183
185
 
@@ -185,17 +187,42 @@ module RubyReportable
185
187
 
186
188
  if filter_validity == false
187
189
  # Ignore an empty filter unless it's required
188
- if !sandbox[:input].blank?
190
+ if !sandbox[:input].to_s.blank?
191
+ errors << "#{filter_name} is invalid."
192
+ false
193
+ else
194
+ if sandbox[:input].to_s.blank? && !filter[:require].blank?
195
+ errors << "#{filter_name} is required."
196
+ false
197
+ else
198
+ true
199
+ end
200
+ end
201
+ elsif filter_validity == true
202
+ if sandbox[:input].to_s.blank? && !filter[:require].blank?
203
+ errors << "#{filter_name} is required."
189
204
  false
190
205
  else
191
206
  true
192
207
  end
193
- else
194
- true
208
+ elsif !filter_validity.nil? && !filter_validity[:status].nil? && filter_validity[:status] == false
209
+ # Ignore an empty filter unless it's required
210
+ if !sandbox[:input].to_s.blank?
211
+ errors << filter_validity[:errors]
212
+ false
213
+ else
214
+ if sandbox[:input].to_s.blank? && !filter[:require].blank?
215
+ errors << "#{filter_name} is required."
216
+ false
217
+ else
218
+ true
219
+ end
220
+ end
195
221
  end
196
222
  end
197
223
 
198
- !validity.include?(false)
224
+ return {:status => !validity.include?(false), :errors => errors}
225
+
199
226
  end # end def valid?
200
227
  end
201
228
  end
@@ -1,3 +1,3 @@
1
1
  module RubyReportable
2
- VERSION = "0.1.3.1"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_reportable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3.1
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-02 00:00:00.000000000 Z
12
+ date: 2013-01-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -96,7 +96,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
96
96
  version: '0'
97
97
  requirements: []
98
98
  rubyforge_project: ruby_reportable
99
- rubygems_version: 1.8.24
99
+ rubygems_version: 1.8.23
100
100
  signing_key:
101
101
  specification_version: 3
102
102
  summary: Ruby Reporting