dao 5.6.1 → 7.0.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.
@@ -57,10 +57,6 @@ module Dao
57
57
  Messages.to_html(self)
58
58
  end
59
59
 
60
- def to_s(*args)
61
- to_html(*args)
62
- end
63
-
64
60
  def Messages.to_text(*args)
65
61
  to_text = []
66
62
  Messages.each(*args) do |message|
@@ -21,7 +21,7 @@ module Dao
21
21
  path.squeeze!('/')
22
22
  path.sub!(%r|^/|, '')
23
23
  path.sub!(%r|/$|, '')
24
- paths = path.split('/')
24
+ path.split('/')
25
25
  end
26
26
 
27
27
  def absolute_path_for(arg, *args)
@@ -54,7 +54,7 @@ module Dao
54
54
  end
55
55
 
56
56
  def match(path)
57
- match = pattern.match(path).to_a
57
+ pattern.match(path).to_a
58
58
  end
59
59
 
60
60
  def params_for(path)
@@ -62,7 +62,7 @@ module Dao
62
62
 
63
63
  unless match.empty?
64
64
  map = Map.new
65
- ignored = match.shift
65
+ _ = match.shift
66
66
  @keys.each_with_index do |key, index|
67
67
  map[key] = match[index]
68
68
  end
@@ -181,7 +181,6 @@ module Dao
181
181
  arg = args.shift
182
182
  case arg
183
183
  when Result
184
- result = arg
185
184
  if arg.errors.nil? or arg.errors.empty? or arg.valid?
186
185
  new(200)
187
186
  else
@@ -189,7 +188,7 @@ module Dao
189
188
  end
190
189
  when Status
191
190
  arg
192
- when Fixnum
191
+ when Integer
193
192
  code = arg
194
193
  message = Code2Message[code]
195
194
  new(code, message)
@@ -276,7 +275,7 @@ module Dao
276
275
  end
277
276
 
278
277
  Groups.each do |code, group|
279
- module_eval <<-__, __FILE__, __LINE__ -1
278
+ module_eval(<<-__, __FILE__, __LINE__ - 1)
280
279
  def Status.#{ group }
281
280
  @status_group_#{ group } ||= Status.for(#{ code })
282
281
  end
@@ -316,7 +315,7 @@ module Dao
316
315
  end
317
316
 
318
317
  def clone
319
- clone = Status.for(code)
318
+ Status.for(code)
320
319
  end
321
320
 
322
321
  def to_json(*args, &block)
@@ -150,7 +150,7 @@ module Dao
150
150
  last_number_index = nil
151
151
 
152
152
  keys.each_with_index do |k, i|
153
- if k.is_a?(Number)
153
+ if k.is_a?(Numeric)
154
154
  last_number_index = i
155
155
  end
156
156
  end
@@ -188,7 +188,7 @@ module Dao
188
188
 
189
189
  begin
190
190
  MultiJson.dump(object, options)
191
- rescue Object => e
191
+ rescue Object => _
192
192
  YAML.load( object.to_yaml ).to_json
193
193
  end
194
194
  end
@@ -173,7 +173,6 @@ class Upload < ::Map
173
173
  attr_accessor :basename
174
174
  attr_accessor :io
175
175
  attr_accessor :tmpdir
176
- attr_accessor :placeholder
177
176
 
178
177
  IOs = {}
179
178
 
@@ -364,9 +364,9 @@ module Dao
364
364
  options = Map.options_for!(args)
365
365
  list = args + Array(options.delete(:keys)) + Array(options.delete(:or))
366
366
 
367
- list.each do |args|
367
+ list.each do |_args|
368
368
  candidates = list.dup
369
- candidates.delete(args)
369
+ candidates.delete(_args)
370
370
 
371
371
  message = options[:message] || "(or #{ candidates.map{|candidate| Array(candidate).join('.')}.join(', ') } ) is blank or missing"
372
372
  allow_nil = options[:allow_nil]
@@ -424,7 +424,7 @@ module Dao
424
424
 
425
425
  m
426
426
  end
427
- validates(*args, &block)
427
+ validates(*_args, &block)
428
428
  end
429
429
  end
430
430
 
@@ -432,9 +432,9 @@ module Dao
432
432
  options = Map.options_for!(args)
433
433
  list = args + Array(options.delete(:keys)) + Array(options.delete(:or))
434
434
 
435
- list.each do |args|
435
+ list.each do |_args|
436
436
  candidates = list.dup
437
- candidates.delete(args)
437
+ candidates.delete(_args)
438
438
 
439
439
  message = options[:message] || "(and #{ candidates.map{|candidate| Array(candidate).join('.')}.join(', ') } ) is blank or missing"
440
440
  allow_nil = options[:allow_nil]
@@ -492,7 +492,7 @@ module Dao
492
492
 
493
493
  m
494
494
  end
495
- validates(*args, &block)
495
+ validates(*_args, &block)
496
496
  end
497
497
  end
498
498
 
@@ -101,7 +101,7 @@ module Dao
101
101
  block = args.pop if args.last.respond_to?(:call)
102
102
  block ||= NotBlank
103
103
  callback = Callback.new(options, &block)
104
- options = Map.options_for!(args)
104
+ Map.options_for!(args)
105
105
  key = key_for(args)
106
106
  validations = stack.validations.last || self.validations
107
107
  validations[key] ||= Callback::Chain.new
@@ -112,7 +112,7 @@ module Dao
112
112
 
113
113
  def validates_each(*args, &block)
114
114
  options = Map.options_for!(args)
115
- key = key_for(args)
115
+ key_for(args)
116
116
 
117
117
  args.push(options)
118
118
 
@@ -299,7 +299,7 @@ module Dao
299
299
  if forcing_validity?
300
300
  true
301
301
  else
302
- options = Map.options_for!(args)
302
+ Map.options_for!(args)
303
303
  run_validations
304
304
  errors.empty? and status.ok?
305
305
  end
@@ -0,0 +1,15 @@
1
+ todo:
2
+
3
+ - minimize deps
4
+
5
+ - inlined test/rails-app/ ?
6
+ - look at use of rails_current, etc
7
+ - exclude from gem
8
+ - wrap/callback support
9
+ - kill validations?
10
+ - kill hooks?
11
+ - simplify lifecycle/initialize
12
+ - simpler prepare cycle
13
+ - api
14
+
15
+ done:
@@ -0,0 +1,207 @@
1
+ # vim: syntax=ruby
2
+ require 'rake/clean'
3
+ require 'digest'
4
+ #------------------------------------------------------------------------------
5
+ # If you want to Develop on this project just run 'rake develop' and you'll
6
+ # have all you need to get going. If you want to use bundler for development,
7
+ # then run 'rake develop:using_bundler'
8
+ #------------------------------------------------------------------------------
9
+ namespace :develop do
10
+
11
+ # Install all the development and runtime dependencies of this gem using the
12
+ # gemspec.
13
+ task :default => 'Gemfile' do
14
+ require 'rubygems/dependency_installer'
15
+ installer = ::Gem::DependencyInstaller.new
16
+ puts "Installing bundler..."
17
+ installer.install 'bundler'
18
+ sh 'bundle install'
19
+ puts "\n\nNow run 'rake test'"
20
+ end
21
+
22
+ # Create a Gemfile that just references the gemspec
23
+ file 'Gemfile' => :gemspec do
24
+ File.open( "Gemfile", "w+" ) do |f|
25
+ f.puts "# DO NOT EDIT - This file is automatically generated"
26
+ f.puts "# Make changes to Manifest.txt and/or Rakefile and regenerate"
27
+ f.puts 'source "https://rubygems.org/"'
28
+ f.puts 'gemspec'
29
+ end
30
+ end
31
+ end
32
+ desc "Boostrap development"
33
+ task :develop => "develop:default"
34
+
35
+ #------------------------------------------------------------------------------
36
+ # Minitest - standard TestTask
37
+ #------------------------------------------------------------------------------
38
+ begin
39
+ require 'rake/testtask'
40
+ Rake::TestTask.new( :test ) do |t|
41
+ t.libs = %w[ lib spec test ]
42
+ t.pattern = "{test,spec}/**/{test_*,*_spec,*_test}.rb"
43
+ end
44
+
45
+ task :test_requirements
46
+ task :test => :test_requirements
47
+ task :default => :test
48
+ rescue LoadError
49
+ This.task_warning( 'test' )
50
+ end
51
+
52
+ #------------------------------------------------------------------------------
53
+ # Manifest - We want an explicit list of thos files that are to be packaged in
54
+ # the gem. Most of this is from Hoe.
55
+ #------------------------------------------------------------------------------
56
+ namespace 'manifest' do
57
+ desc "Check the manifest"
58
+ task :check => :clean do
59
+ files = FileList["**/*", ".*"].exclude( This.exclude_from_manifest ).to_a.sort
60
+ files = files.select{ |f| File.file?( f ) }
61
+
62
+ tmp = "Manifest.tmp"
63
+ File.open( tmp, 'w' ) do |f|
64
+ f.puts files.join("\n")
65
+ end
66
+
67
+ begin
68
+ sh "diff -du Manifest.txt #{tmp}"
69
+ ensure
70
+ rm tmp
71
+ end
72
+ puts "Manifest looks good"
73
+ end
74
+
75
+ desc "Generate the manifest"
76
+ task :generate => :clean do
77
+ files = %x[ git ls-files ].split("\n").sort
78
+ files.reject! { |f| f =~ This.exclude_from_manifest }
79
+ File.open( "Manifest.txt", "w" ) do |f|
80
+ f.puts files.join("\n")
81
+ end
82
+ end
83
+ end
84
+
85
+ #------------------------------------------------------------------------------
86
+ # Fixme - look for fixmes and report them
87
+ #------------------------------------------------------------------------------
88
+ namespace :fixme do
89
+ task :default => 'manifest:check' do
90
+ This.manifest.each do |file|
91
+ next if file == __FILE__
92
+ next unless file =~ %r/(txt|rb|md|rdoc|css|html|xml|css)\Z/
93
+ puts "FIXME: Rename #{file}" if file =~ /fixme/i
94
+ IO.readlines( file ).each_with_index do |line, idx|
95
+ prefix = "FIXME: #{file}:#{idx+1}".ljust(42)
96
+ puts "#{prefix} => #{line.strip}" if line =~ /fixme/i
97
+ end
98
+ end
99
+ end
100
+
101
+ def fixme_project_root
102
+ This.project_path( '../fixme' )
103
+ end
104
+
105
+ def fixme_project_path( subtree )
106
+ fixme_project_root.join( subtree )
107
+ end
108
+
109
+ def local_fixme_files
110
+ This.manifest.select { |p| p =~ %r|^tasks/| }
111
+ end
112
+
113
+ def outdated_fixme_files
114
+ local_fixme_files.select do |local|
115
+ upstream = fixme_project_path( local )
116
+ upstream.exist? &&
117
+ ( Digest::SHA256.file( local ) != Digest::SHA256.file( upstream ) )
118
+ end
119
+ end
120
+
121
+ def fixme_up_to_date?
122
+ outdated_fixme_files.empty?
123
+ end
124
+
125
+ desc "See if the fixme tools are outdated"
126
+ task :outdated => :release_check do
127
+ if fixme_up_to_date? then
128
+ puts "Fixme files are up to date."
129
+ else
130
+ outdated_fixme_files.each do |f|
131
+ puts "#{f} is outdated"
132
+ end
133
+ end
134
+ end
135
+
136
+ desc "Update outdated fixme files"
137
+ task :update => :release_check do
138
+ if fixme_up_to_date? then
139
+ puts "Fixme files are already up to date."
140
+ else
141
+ puts "Updating fixme files:"
142
+ outdated_fixme_files.each do |local|
143
+ upstream = fixme_project_path( local )
144
+ puts " * #{local}"
145
+ FileUtils.cp( upstream, local )
146
+ end
147
+ puts "Use your git commands as appropriate."
148
+ end
149
+ end
150
+ end
151
+ desc "Look for fixmes and report them"
152
+ task :fixme => "fixme:default"
153
+
154
+ #------------------------------------------------------------------------------
155
+ # Gem Specification
156
+ #------------------------------------------------------------------------------
157
+ # Really this is only here to support those who use bundler
158
+ desc "Build the #{This.name}.gemspec file"
159
+ task :gemspec do
160
+ File.open( This.gemspec_file, "wb+" ) do |f|
161
+ f.puts "# DO NOT EDIT - This file is automatically generated"
162
+ f.puts "# Make changes to Manifest.txt and/or Rakefile and regenerate"
163
+ f.write This.platform_gemspec.to_ruby
164
+ end
165
+ end
166
+
167
+ # .rbc files from ruby 2.0
168
+ CLOBBER << FileList["**/*.rbc"]
169
+
170
+ # The standard gem packaging task, everyone has it.
171
+ require 'rubygems/package_task'
172
+ ::Gem::PackageTask.new( This.platform_gemspec ) do
173
+ # nothing
174
+ end
175
+
176
+ #------------------------------------------------------------------------------
177
+ # Release - the steps we go through to do a final release, this is pulled from
178
+ # a compbination of mojombo's rakegem, hoe and hoe-git
179
+ #
180
+ # 1) make sure we are on the master branch
181
+ # 2) make sure there are no uncommitted items
182
+ # 3) check the manifest and make sure all looks good
183
+ # 4) build the gem
184
+ # 5) do an empty commit to have the commit message of the version
185
+ # 6) tag that commit as the version
186
+ # 7) push master
187
+ # 8) push the tag
188
+ # 7) pus the gem
189
+ #------------------------------------------------------------------------------
190
+ task :release_check do
191
+ unless `git branch` =~ /^\* master$/
192
+ abort "You must be on the master branch to release!"
193
+ end
194
+ unless `git status` =~ /^nothing to commit/m
195
+ abort "Nope, sorry, you have unfinished business"
196
+ end
197
+ end
198
+
199
+ desc "Create tag v#{This.version}, build and push #{This.platform_gemspec.full_name} to rubygems.org"
200
+ task :release => [ :release_check, 'manifest:check', :gem ] do
201
+ sh "git commit --allow-empty -a -m 'Release #{This.version}'"
202
+ sh "git tag -a -m 'v#{This.version}' v#{This.version}"
203
+ sh "git push origin master"
204
+ sh "git push origin v#{This.version}"
205
+ sh "gem push pkg/#{This.platform_gemspec.full_name}.gem"
206
+ end
207
+
@@ -0,0 +1,207 @@
1
+ require 'pathname'
2
+
3
+ # Public: A Class containing all the metadata and utilities needed to manage a
4
+ # ruby project.
5
+ class ThisProject
6
+ # The name of this project
7
+ attr_accessor :name
8
+
9
+ # The author's name
10
+ attr_accessor :author
11
+
12
+ # The email address of the author(s)
13
+ attr_accessor :email
14
+
15
+ # The homepage of this project
16
+ attr_accessor :homepage
17
+
18
+ # The regex of files to exclude from the manifest
19
+ attr_accessor :exclude_from_manifest
20
+
21
+ # The hash of Gem::Specifications keyed' by platform
22
+ attr_accessor :gemspecs
23
+
24
+ # Public: Initialize ThisProject
25
+ #
26
+ # Yields self
27
+ def initialize(&block)
28
+ @exclude_from_manifest = Regexp.union(/\.(git|DS_Store)/,
29
+ /^(doc|coverage|pkg|tmp|Gemfile(\.lock)?)/,
30
+ /^[^\/]+\.gemspec/,
31
+ /\.(swp|jar|bundle|so|rvmrc|travis.yml)$/,
32
+ /~$/)
33
+ @gemspecs = Hash.new
34
+ yield self if block_given?
35
+ end
36
+
37
+ # Public: return the version of ThisProject
38
+ #
39
+ # Search the ruby files in the project looking for the one that has the
40
+ # version string in it. This does not eval any code in the project, it parses
41
+ # the source code looking for the string.
42
+ #
43
+ # Returns a String version
44
+ def version
45
+ [ "lib/#{ name }.rb", "lib/#{ name }/version.rb" ].each do |v|
46
+ path = project_path( v )
47
+ next unless path.exist?
48
+ line = path.read[/^\s*VERSION\s*=\s*.*/i]
49
+ if line then
50
+ return line.match(/.*VERSION\s*=\s*['"](.*)['"]/i)[1]
51
+ end
52
+ end
53
+ end
54
+
55
+ # Internal: Return a section of an RDoc file with the given section name
56
+ #
57
+ # path - the relative path in the project of the file to parse
58
+ # section_name - the section out of the file from which to parse data
59
+ #
60
+ # Retuns the text of the section as an array of paragrphs.
61
+ def section_of( file, section_name )
62
+ re = /^[=#]+ (.*)$/
63
+ sectional = project_path( file )
64
+ parts = sectional.read.split( re )[1..-1]
65
+ parts.map! { |p| p.strip }
66
+
67
+ sections = Hash.new
68
+ Hash[*parts].each do |k,v|
69
+ sections[k] = v.split("\n\n")
70
+ end
71
+ return sections[section_name]
72
+ end
73
+
74
+ # Internal: print out a warning about the give task
75
+ def task_warning( task )
76
+ warn "WARNING: '#{task}' tasks are not defined. Please run 'rake develop'"
77
+ end
78
+
79
+ # Internal: Return the full path to the file that is relative to the project
80
+ # root.
81
+ #
82
+ # path - the relative path of the file from the project root
83
+ #
84
+ # Returns the Pathname of the file
85
+ def project_path( *relative_path )
86
+ project_root.join( *relative_path )
87
+ end
88
+
89
+ # Internal: The absolute path of this file
90
+ #
91
+ # Returns the Pathname of this file.
92
+ def this_file_path
93
+ Pathname.new( __FILE__ ).expand_path
94
+ end
95
+
96
+ # Internal: The root directory of this project
97
+ #
98
+ # This is defined as being the directory that is in the path of this project
99
+ # that has the first Rakefile
100
+ #
101
+ # Returns the Pathname of the directory
102
+ def project_root
103
+ this_file_path.ascend do |p|
104
+ rakefile = p.join( 'Rakefile' )
105
+ return p if rakefile.exist?
106
+ end
107
+ end
108
+
109
+ # Internal: Returns the contents of the Manifest.txt file as an array
110
+ #
111
+ # Returns an Array of strings
112
+ def manifest
113
+ manifest_file = project_path( "Manifest.txt" )
114
+ abort "You need a Manifest.txt" unless manifest_file.readable?
115
+ manifest_file.readlines.map { |l| l.strip }
116
+ end
117
+
118
+ # Internal: Return the files that define the extensions
119
+ #
120
+ # Returns an Array
121
+ def extension_conf_files
122
+ manifest.grep( /extconf.rb\Z/ )
123
+ end
124
+
125
+ # Internal: Returns the gemspace associated with the current ruby platform
126
+ def platform_gemspec
127
+ gemspecs.fetch(platform) { This.ruby_gemspec }
128
+ end
129
+
130
+ def core_gemspec
131
+ Gem::Specification.new do |spec|
132
+ spec.name = name
133
+ spec.version = version
134
+ spec.author = author
135
+ spec.email = email
136
+ spec.homepage = homepage
137
+
138
+ spec.summary = summary
139
+ spec.description = description
140
+ spec.license = license
141
+
142
+ spec.files = manifest
143
+ spec.executables = spec.files.grep(/^bin/) { |f| File.basename(f) }
144
+ spec.test_files = spec.files.grep(/^spec/)
145
+
146
+ spec.extra_rdoc_files += spec.files.grep(/(txt|rdoc|md)$/)
147
+ spec.rdoc_options = [ "--main" , 'README.md',
148
+ "--markup", "tomdoc" ]
149
+
150
+ spec.required_ruby_version = '>= 2.2.0'
151
+ end
152
+ end
153
+
154
+ # Internal: Return the gemspec for the ruby platform
155
+ def ruby_gemspec( core = core_gemspec, &block )
156
+ yielding_gemspec( 'ruby', core, &block )
157
+ end
158
+
159
+ # Internal: Return the gemspec for the jruby platform
160
+ def java_gemspec( core = core_gemspec, &block )
161
+ yielding_gemspec( 'java', core, &block )
162
+ end
163
+
164
+ # Internal: give an initial spec and a key, create a new gemspec based off of
165
+ # it.
166
+ #
167
+ # This will force the new gemspecs 'platform' to be that of the key, since the
168
+ # only reason you would have multiple gemspecs at this point is to deal with
169
+ # different platforms.
170
+ def yielding_gemspec( key, core )
171
+ spec = gemspecs[key] ||= core.dup
172
+ spec.platform = key
173
+ yield spec if block_given?
174
+ return spec
175
+ end
176
+
177
+ # Internal: Return the platform of ThisProject at the current moment in time.
178
+ def platform
179
+ (RUBY_PLATFORM == "java") ? 'java' : Gem::Platform::RUBY
180
+ end
181
+
182
+ # Internal: Return the DESCRIPTION section of the README.rdoc file
183
+ def description_section
184
+ section_of( 'README.md', 'DESCRIPTION')
185
+ end
186
+
187
+ # Internal: Return the summary text from the README
188
+ def summary
189
+ description_section.first
190
+ end
191
+
192
+ # Internal: Return the full description text from the README
193
+ def description
194
+ description_section.join(" ").tr("\n", ' ').gsub(/[{}]/,'').gsub(/\[[^\]]+\]/,'') # strip rdoc
195
+ end
196
+
197
+ def license
198
+ "ISC"
199
+ end
200
+
201
+ # Internal: The path to the gemspec file
202
+ def gemspec_file
203
+ project_path( "#{ name }.gemspec" )
204
+ end
205
+ end
206
+
207
+ This = ThisProject.new