clearbooks 0.16.3

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.
Files changed (74) hide show
  1. checksums.yaml +7 -0
  2. data/AUTHORS.md +31 -0
  3. data/CHANGELOG.md +0 -0
  4. data/COPYING.md +12 -0
  5. data/FAQ.md +8 -0
  6. data/Gemfile +105 -0
  7. data/LICENSE.md +14 -0
  8. data/MAINTAINERS.md +40 -0
  9. data/README.md +549 -0
  10. data/Rakefile +94 -0
  11. data/Thorfile +80 -0
  12. data/bin/clearbooks +28 -0
  13. data/clearbooks.gemspec +119 -0
  14. data/examples/demo.rb +8 -0
  15. data/lib/clearbooks.rb +92 -0
  16. data/lib/clearbooks/core_ext.rb +8 -0
  17. data/lib/clearbooks/core_ext/array.rb +51 -0
  18. data/lib/clearbooks/core_ext/hash.rb +47 -0
  19. data/lib/clearbooks/core_ext/io_binary_read.rb +20 -0
  20. data/lib/clearbooks/core_ext/string.rb +21 -0
  21. data/lib/clearbooks/error.rb +8 -0
  22. data/lib/clearbooks/error/errors.rb +228 -0
  23. data/lib/clearbooks/interface/rake/cucumber.rb +36 -0
  24. data/lib/clearbooks/interface/rake/default.rb +28 -0
  25. data/lib/clearbooks/interface/rake/documentation.rb +45 -0
  26. data/lib/clearbooks/interface/rake/guard.rb +13 -0
  27. data/lib/clearbooks/interface/rake/helpers.rb +27 -0
  28. data/lib/clearbooks/interface/rake/library.rb +126 -0
  29. data/lib/clearbooks/interface/rake/metric.rb +15 -0
  30. data/lib/clearbooks/interface/rake/rspec.rb +31 -0
  31. data/lib/clearbooks/interface/thor/info.thor +292 -0
  32. data/lib/clearbooks/interface/thor/mixin/config_choice.rb +27 -0
  33. data/lib/clearbooks/interface/thor/mixin/configuration.rb +28 -0
  34. data/lib/clearbooks/interface/thor/mixin/default.rb +30 -0
  35. data/lib/clearbooks/interface/thor/mixin/default_config.rb +31 -0
  36. data/lib/clearbooks/interface/thor/mixin/guess.rb +57 -0
  37. data/lib/clearbooks/interface/thor/mixin/shell.rb +225 -0
  38. data/lib/clearbooks/interface/thor/version.thor +34 -0
  39. data/lib/clearbooks/library/client.rb +257 -0
  40. data/lib/clearbooks/library/configuration.rb +34 -0
  41. data/lib/clearbooks/model/account_code.rb +65 -0
  42. data/lib/clearbooks/model/base.rb +67 -0
  43. data/lib/clearbooks/model/entity.rb +225 -0
  44. data/lib/clearbooks/model/invoice.rb +163 -0
  45. data/lib/clearbooks/model/item.rb +78 -0
  46. data/lib/clearbooks/model/journal.rb +74 -0
  47. data/lib/clearbooks/model/ledger.rb +52 -0
  48. data/lib/clearbooks/model/payment.rb +113 -0
  49. data/lib/clearbooks/model/project.rb +58 -0
  50. data/lib/clearbooks/version.rb +12 -0
  51. data/spec/clearbooks/clearbooks_spec.rb +27 -0
  52. data/spec/clearbooks/model/account_code_spec.rb +52 -0
  53. data/spec/clearbooks/model/entity_spec.rb +107 -0
  54. data/spec/clearbooks/model/invoice_spec.rb +109 -0
  55. data/spec/clearbooks/model/journal_spec.rb +77 -0
  56. data/spec/clearbooks/model/payment_spec.rb +103 -0
  57. data/spec/clearbooks/model/project_spec.rb +72 -0
  58. data/spec/fixtures/response/allocate_payment.xml +12 -0
  59. data/spec/fixtures/response/create_entity.xml +12 -0
  60. data/spec/fixtures/response/create_invoice.xml +11 -0
  61. data/spec/fixtures/response/create_journal.xml +12 -0
  62. data/spec/fixtures/response/create_payment.xml +12 -0
  63. data/spec/fixtures/response/create_project.xml +12 -0
  64. data/spec/fixtures/response/delete_entity.xml +12 -0
  65. data/spec/fixtures/response/delete_journal.xml +12 -0
  66. data/spec/fixtures/response/list_account_codes.xml +168 -0
  67. data/spec/fixtures/response/list_entities.xml +45 -0
  68. data/spec/fixtures/response/list_invoices.xml +56 -0
  69. data/spec/fixtures/response/list_projects.xml +16 -0
  70. data/spec/fixtures/response/no_api_key_fault.xml +8 -0
  71. data/spec/fixtures/response/well_formed_request.xml +10 -0
  72. data/spec/fixtures/response/wrong_api_key_fault.xml +8 -0
  73. data/spec/spec_helper.rb +26 -0
  74. metadata +212 -0
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env ruby
2
+
3
+
4
+ # System
5
+ require 'shellwords'
6
+ require 'fileutils'
7
+
8
+ require 'date'
9
+ require 'ostruct'
10
+
11
+
12
+
13
+ ### Actions
14
+
15
+ desc "Look for TODO and FIXME tags in the code" # {{{
16
+ task :todo do
17
+ egrep /(FIXME|TODO|TBD|FIXME1|FIXME2|FIXME3)/
18
+ end # }}}
19
+
20
+ desc "Git Tag number of this repo" # {{{
21
+ task :version do |t|
22
+ # sh 'git describe --abbrev=0 --tags'
23
+ sh 'git describe --tags'
24
+ end # }}}
25
+
26
+
27
+ # vim:ts=2:tw=100:wm=100:syntax=ruby
@@ -0,0 +1,126 @@
1
+ #!/usr/bin/env ruby
2
+
3
+
4
+ # System
5
+ require 'shellwords'
6
+ require 'fileutils'
7
+
8
+ require 'date'
9
+ require 'ostruct'
10
+
11
+
12
+ ### Helper Functions
13
+
14
+ # @fn def egrep(pattern) # {{{
15
+ # @brief Searches for a given regular expression among all ruby files
16
+ #
17
+ # @param [Regexp] pattern Regular Expression pattern class
18
+ def egrep( pattern )
19
+
20
+ Dir[ "**/*.{rb,thor,rake}" ].each do |fn|
21
+ count = 0
22
+ open(fn) do |f|
23
+
24
+ while line = f.gets
25
+ count += 1
26
+ STDOUT.puts "#{fn}:#{count}:#{line}" if line =~ pattern
27
+ end
28
+
29
+ end # end of open
30
+ end # end of Dir.each
31
+
32
+ end # }}}
33
+
34
+ # @fn def clean target # {{{
35
+ # @brief Clean output from folder
36
+ #
37
+ # @param [String] target Target folder to clean
38
+ def clean target
39
+
40
+ files = Dir.glob( File.join( target, "*" ) )
41
+
42
+ files.each do |file|
43
+ print "(--) "
44
+ sh "rm -vrf #{file.to_s}" if( File.exists?( "#{file.to_s}" ) )
45
+ end
46
+
47
+ end # }}}
48
+
49
+ # @fn def colorize color, message {{{
50
+ # @brief The function colorize takes a message and wraps it into standard color commands such as for bash.
51
+ #
52
+ # @param [String] color The colorname in plain english. e.g. "LightGray", "Gray", "Red", "BrightRed"
53
+ # @param [String] message The message which should be wrapped
54
+ #
55
+ # @return [String] Colorized message string
56
+ #
57
+ # @warning Might not work for your terminal
58
+ #
59
+ # FIXME: Implement bold behavior
60
+ # FIXME: This method is currently b0rked
61
+ def colorize color, message
62
+
63
+ # Black 0;30 Dark Gray 1;30
64
+ # Blue 0;34 Light Blue 1;34
65
+ # Green 0;32 Light Green 1;32
66
+ # Cyan 0;36 Light Cyan 1;36
67
+ # Red 0;31 Light Red 1;31
68
+ # Purple 0;35 Light Purple 1;35
69
+ # Brown 0;33 Yellow 1;33
70
+ # Light Gray 0;37 White 1;37
71
+
72
+ colors = {
73
+ "Gray" => "\e[1;30m",
74
+ "LightGray" => "\e[0;37m",
75
+ "Cyan" => "\e[0;36m",
76
+ "LightCyan" => "\e[1;36m",
77
+ "Blue" => "\e[0;34m",
78
+ "LightBlue" => "\e[1;34m",
79
+ "Green" => "\e[0;32m",
80
+ "LightGreen" => "\e[1;32m",
81
+ "Red" => "\e[0;31m",
82
+ "LightRed" => "\e[1;31m",
83
+ "LightRedBlink" => "\e[5;31m",
84
+ "Purple" => "\e[0;35m",
85
+ "LightPurple" => "\e[1;35m",
86
+ "Brown" => "\e[0;33m",
87
+ "Yellow" => "\e[1;33m",
88
+ "White" => "\e[1;37m"
89
+ }
90
+ nocolor = "\e[0m"
91
+
92
+ colors[ color ] + message + nocolor
93
+ end # of def colorize }}}
94
+
95
+ # @fn def message level, msg {{{
96
+ # @brief The function message will take a message as argument as well as a level (e.g. "info", "ok", "error", "question", "debug") which then would print
97
+ # ( "(--) msg..", "(II) msg..", "(EE) msg..", "(??) msg..")
98
+ #
99
+ # @param [Symbol] level Can either be :info, :success, :error or :question
100
+ # @param [String] msg Represents the message you want to send to stdout (info, ok, question) stderr (error)
101
+ #
102
+ # Helpers: colorize
103
+ def message level, msg
104
+
105
+ symbols = {
106
+ :info => [ "(--)", "Brown" ],
107
+ :success => [ "(II)", "LightGreen" ],
108
+ :error => [ "(EE)", "LightRed" ],
109
+ :question => [ "(??)", "LightCyan" ],
110
+ :debug => [ "(++)", "LightBlue" ],
111
+ :warning => [ "(WW)", "Yellow" ]
112
+ }
113
+
114
+ raise ArugmentError, "Can't find the corresponding symbol for this message level (#{level.to_s}) - is the spelling wrong?" unless( symbols.key?( level ) )
115
+
116
+ if( level == :error )
117
+ STDERR.puts colorize( symbols[ level.to_sym ].last, "#{symbols[ level.to_sym ].first.to_s} #{msg.to_s}" )
118
+ else
119
+ STDOUT.puts colorize( symbols[ level.to_sym ].last, "#{symbols[ level.to_sym ].first.to_s} #{msg.to_s}" )
120
+ end
121
+
122
+ end # of def message }}}
123
+
124
+
125
+
126
+ # vim:ts=2:tw=100:wm=100:syntax=ruby
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+
3
+
4
+
5
+ namespace :metric do
6
+
7
+ desc "Run metric fu for project" # {{{
8
+ task :metric do |t|
9
+ puts "(--) Running metric fu"
10
+ system "metric_fu"
11
+ end # }}}
12
+
13
+ end # of namespace :metric
14
+
15
+ # vim:ts=2:tw=100:wm=100:syntax=ruby
@@ -0,0 +1,31 @@
1
+ #!/usr/bin/env ruby
2
+
3
+
4
+ ## Handle RSpec 1.x and 2.x branches # {{{
5
+ #
6
+ # dm-redis-adapter and others maybe need 1.x while we want 2.x is possible.
7
+ begin
8
+
9
+ require 'rspec/core/rake_task'
10
+
11
+ desc "RSpec Core Tasks" # {{{
12
+ RSpec::Core::RakeTask.new(:spec) do |t|
13
+ t.rspec_opts = '--format NyanCatFormatter --color --fail-fast --order random'
14
+ end # }}}
15
+
16
+ rescue LoadError
17
+
18
+ puts "(WW) Could not load RSpec 2.x branch, falling back to 1.x."
19
+
20
+ require 'spec/rake/spectask'
21
+
22
+ desc "Run specs" # {{{
23
+ Spec::Rake::SpecTask.new do |t|
24
+ t.spec_files = FileList['spec/**/*_spec.rb']
25
+ t.spec_opts = %w(-fs --color)
26
+ end # }}}
27
+
28
+ end # }}}
29
+
30
+
31
+ # vim:ts=2:tw=100:wm=100:syntax=ruby
@@ -0,0 +1,292 @@
1
+ #!/usr/bin/env ruby
2
+
3
+
4
+ # System includes
5
+ require 'ostruct'
6
+ require 'andand'
7
+ require 'tempfile'
8
+ require 'awesome_print'
9
+ require 'os'
10
+
11
+ # Custom includes
12
+ require File.expand_path( File.dirname( __FILE__ ) + '/mixin/shell' )
13
+
14
+
15
+ # @class Info command class
16
+ # @brief Implements the info command
17
+ class Info < Thor
18
+
19
+ include ::Mixin::Shell
20
+ # include ::Mixin::Command
21
+
22
+ default_task :info
23
+
24
+ class_option :'without-general', :type => :boolean, :desc => "Print general system environment information"
25
+ class_option :'without-project', :type => :boolean, :desc => "Print project environment information"
26
+ class_option :'without-ruby', :type => :boolean, :desc => "Print ruby environment information"
27
+
28
+ class_option :pretty, :type => :boolean, :desc => "Pretty print"
29
+
30
+
31
+ ## API
32
+
33
+ # @fn def info {{{
34
+ # @brief Main info task entry point
35
+ desc "overview", "Shows system overview"
36
+ def overview
37
+
38
+ # Default symbol action list to find info for
39
+ default = %i(
40
+ general
41
+ project
42
+ ruby
43
+ )
44
+
45
+ # Make sure if we have a --without-* opts to skip work
46
+ options.each_pair do |option, skip|
47
+ next unless( skip )
48
+ default.delete_if { |item| option =~ %r{#{item.to_s}}i }
49
+ end
50
+
51
+ # Execute scan & print
52
+ default.each do |item|
53
+ data = scan_for item
54
+ next if data.andand.broken.nil?
55
+
56
+ self.send :pretty_print, data
57
+ end # of default.each
58
+
59
+ end # }}}
60
+
61
+
62
+ private
63
+
64
+ no_tasks do
65
+
66
+ ## Actions
67
+
68
+ # @fn def scan_for what # {{{
69
+ # @brief When executed will run "what" method scanner and print relevant information
70
+ #
71
+ # @param [Symbol] what Symbol of scanner method to run, e.g. :general, :java, :ruby etc.
72
+ def scan_for what
73
+ result = nil
74
+
75
+ begin
76
+ result = self.send what
77
+ rescue Exception => e
78
+ say "(EE) " + e.message, :red
79
+ result = OpenStruct.new
80
+ result.broken = true
81
+ end
82
+
83
+ return result
84
+ end # }}}
85
+
86
+ # @fn def pretty_print information, playful = options[:pretty] # {{{
87
+ # @brief Pretty prints given data to stdout
88
+ #
89
+ # @param [OpenStruct] information Information gathered from other scanning methods, e.g. :ruby
90
+ # @param [Boolean] playful Prints some curses like lines if true
91
+ def pretty_print information, playful = options[:pretty]
92
+ begin
93
+ puts ""
94
+ say information.title, :yellow
95
+
96
+ if( playful )
97
+ puts "-"*26
98
+ puts " "*26 + "\\"
99
+ else
100
+ puts ""
101
+ end
102
+
103
+ values = information.send :table
104
+ raise ArgumentError, "Information openstruct is malformed" if( values[ :broken ] )
105
+
106
+ values.each do |key, value|
107
+
108
+ # Skip :broken, :title
109
+ next if( %i(title broken).include?( key.to_sym ) )
110
+
111
+ # Make sure value is a string
112
+ value = value.to_s
113
+
114
+ # Remove pre- and post-padding
115
+ value.strip!
116
+
117
+ # Turn key into a nice printable value
118
+ # e.g. :current_directory => Current directory
119
+ description = key.to_s
120
+ description.gsub!( "_", " " )
121
+ description.capitalize!
122
+
123
+
124
+ # Check if value is multi-line, if so, format accordingly
125
+ output = []
126
+
127
+ if( value =~ %r{\n} )
128
+ lines = value.split( "\n" )
129
+ output << sprintf( "%-25s | %s", description, lines.shift )
130
+ lines.each { |line| output << sprintf( "%-25s | %s", "", line ) }
131
+ else
132
+ output << sprintf( "%-25s | %s", description, value )
133
+ end
134
+
135
+ output.each { |something| say something }
136
+ end
137
+
138
+ if( playful )
139
+ puts " "*26 + "\\"
140
+ puts " "*27 + "-"*80
141
+ end
142
+
143
+ puts ""
144
+
145
+ rescue Exception => e
146
+ say "(EE) " + e.message, :red
147
+ end
148
+ end # }}}
149
+
150
+
151
+ ## Specific Scanners
152
+
153
+ # @fn def general {{{
154
+ # @brief Returns information collected from the general system
155
+ #
156
+ # @return [OpenStruct] Returns openstruct with gathered information
157
+ def general
158
+ result = nil
159
+
160
+ begin
161
+ result = OpenStruct.new
162
+ result.broken = false
163
+
164
+ os = os_report
165
+
166
+ result.title = "System Information"
167
+ result.system = os.host
168
+ result.cpus = OS.cpu_count
169
+ result.architecture = OS.bits
170
+ result.current_user = `whoami`.chomp
171
+
172
+ rescue Exception => e
173
+ result = OpenStruct.new
174
+ result.broken = true
175
+
176
+ say "(EE) " + e.message, :red
177
+ end
178
+
179
+ return result
180
+ end # }}}
181
+
182
+ # @fn def project {{{
183
+ # @brief Print project related information to stdout
184
+ #
185
+ # @return [OpenStruct] Returns openstruct with gathered information
186
+ def project
187
+ result = nil
188
+
189
+ begin
190
+ result = OpenStruct.new
191
+ result.broken = false
192
+
193
+ result.title = "Project information"
194
+
195
+ result.current_directory = Dir.pwd
196
+ result.version = `git describe --tags` || "unknown"
197
+
198
+ rescue Exception => e
199
+ result = OpenStruct.new
200
+ result.broken = true
201
+
202
+ say "(EE) " + e.message, :red
203
+ end
204
+
205
+ return result
206
+ end # }}}
207
+
208
+ # @fn def ruby {{{
209
+ # @brief Prints ruby environment information to stdout
210
+ #
211
+ # @return [OpenStruct] Returns openstruct with gathered information
212
+ def ruby
213
+
214
+ result = nil
215
+
216
+ begin
217
+ result = OpenStruct.new
218
+ result.broken = false
219
+
220
+ result.title = 'Ruby Information'
221
+
222
+ commands = %w(ruby rvm rbenv rake gem)
223
+
224
+ commands.each do |command|
225
+ next unless( self.which( command ) )
226
+
227
+ result.send "#{command}=", self.version( command )
228
+ end
229
+
230
+ rescue Exception => e
231
+ result = OpenStruct.new
232
+ result.broken = true
233
+
234
+ say "(EE) " + e.message, :red
235
+ end
236
+
237
+ return result
238
+ end # }}}
239
+
240
+
241
+ ## Helpers
242
+
243
+ # @fn def os_report {{{
244
+ # @brief Get overview of the Operating System
245
+ #
246
+ # @return [OpenStruct] Returns a openstruct with various information, e.g.
247
+ # arch, target_os, target_vendor, target_cpu, target, host_os, host_vendor, host_cpu, host, RUBY_PLATFORM
248
+ def os_report
249
+ result = nil
250
+
251
+ begin
252
+ yaml = OS.report
253
+ hash = YAML.load( yaml )
254
+ result = hashes_to_ostruct( hash )
255
+ rescue Exception => e
256
+ $stderr.puts set_color "(EE) #{e.message}", :red
257
+ end
258
+
259
+ result
260
+ end # }}}
261
+
262
+ # @fn def hashes_to_ostruct object # {{{
263
+ # @brief This function turns a nested hash into a nested open struct
264
+ #
265
+ # @author Dave Dribin
266
+ # Reference: http://www.dribin.org/dave/blog/archives/2006/11/17/hashes_to_ostruct/
267
+ #
268
+ # @param [Object] object Value can either be of type Hash or Array, if other then it is returned and not changed
269
+ #
270
+ # @return [OStruct] Returns nested open structs
271
+ def hashes_to_ostruct object
272
+
273
+ return case object
274
+ when Hash
275
+ object = object.clone
276
+ object.each { |key, value| object[key] = hashes_to_ostruct(value) }
277
+ OpenStruct.new( object )
278
+ when Array
279
+ object = object.clone
280
+ object.map! { |i| hashes_to_ostruct(i) }
281
+ else
282
+ object
283
+ end
284
+
285
+ end # of def hashes_to_ostruct }}}
286
+
287
+ end # of no_tasks do
288
+
289
+ end # of Class Info
290
+
291
+
292
+ # vim:ts=2:tw=100:wm=100:syntax=ruby