mikado 0.0.3 → 0.0.4

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 CHANGED
@@ -4,6 +4,6 @@ source "http://rubygems.org"
4
4
  gemspec
5
5
 
6
6
  group :test do
7
- gem 'activerecord', '2.3.5', :require => 'active_record'
7
+ gem 'activerecord', '3.0.3', :require => 'active_record'
8
8
  gem 'sqlite3'
9
9
  end
data/README CHANGED
@@ -1,5 +1,7 @@
1
1
  Mikado wraps Activerecord validation conditions with a block.
2
2
 
3
+ Mikado has been tested with ruby 1.8/1.9 and ActiveRecord >= 2.3.5
4
+
3
5
  Example:
4
6
 
5
7
  Instead of
data/Rakefile CHANGED
@@ -10,7 +10,7 @@ task :default do
10
10
  end
11
11
 
12
12
  Dir['test/*_test.rb'].each do |file|
13
- require file
13
+ require File.expand_path("../#{file}", __FILE__)
14
14
  end
15
15
  end
16
16
 
@@ -19,7 +19,7 @@ namespace :db do
19
19
  desc "create and prepare test database"
20
20
  task :prepare do
21
21
  Dir.mkdir('test/db') unless File.directory?('test/db')
22
- require 'test/prepare'
22
+ require File.expand_path("../test/prepare", __FILE__)
23
23
  end
24
24
 
25
25
  desc "delete test database"
@@ -1 +1,2 @@
1
- require File.expand_path('../mikado/conditional_validation', __FILE__)
1
+ require File.expand_path('../mikado/conditional_validation', __FILE__)
2
+ require File.expand_path('../mikado/utility', __FILE__)
@@ -36,26 +36,17 @@ module Mikado
36
36
  end
37
37
 
38
38
  def modify_validations
39
- methods.map { |m| m if m.starts_with?("validates_") }.compact.each do |method|
40
- (class << self; self; end).instance_eval do
41
-
42
- define_method "#{method}_with_mikado" do |*attr_names|
43
- attrs = modify_with_mikado(attr_names)
44
- return self.send("#{method}_without_mikado", *attrs)
45
- end
46
-
47
- alias_method_chain method, "mikado"
48
- end
49
- end
39
+ meths = methods.map { |m| m if m.to_s.starts_with?("validates_") }.compact
40
+ meths |= %w( validate validate_on_create validate_on_update )
50
41
 
51
- %w( validate validate_on_create validate_on_update ).each do |method|
42
+ meths.each do |method|
52
43
  (class << self; self; end).instance_eval do
53
44
 
54
45
  define_method "#{method}_with_mikado" do |*attr_names, &block|
55
46
  attrs = modify_with_mikado(attr_names)
56
47
  return self.send("#{method}_without_mikado", *attrs, &block)
57
48
  end
58
-
49
+
59
50
  alias_method_chain method, "mikado"
60
51
  end
61
52
  end
@@ -65,16 +56,17 @@ module Mikado
65
56
  return attr_names unless mikado_validation
66
57
 
67
58
  options = attr_names.extract_options!
59
+ options = options.dup if Mikado::Utility.is_ar_3?
60
+
68
61
  options[:if] = [] if options.blank?
69
62
  options[:if] = [options[:if]] if !options[:if].is_a?(Array)
70
-
63
+
71
64
  options[:if] = options[:if] | mikado_validation
72
65
 
73
66
  attr_names << options
74
67
 
75
68
  attr_names
76
69
  end
77
-
78
70
 
79
71
  end
80
72
  end
@@ -0,0 +1,20 @@
1
+ module Mikado
2
+ class Utility
3
+ def self.is_ar_3?
4
+ cmp_ar_version(3)
5
+ end
6
+
7
+ def self.is_ar_2?
8
+ cmp_ar_version(2)
9
+ end
10
+
11
+ def self.ar_version
12
+ ActiveRecord::VERSION::STRING
13
+ end
14
+
15
+ # MAJOR (, MINOR, TINY)
16
+ def self.cmp_ar_version(major)
17
+ ar_version =~ /#{major}\.\d+\.\d+/
18
+ end
19
+ end
20
+ end
@@ -1,3 +1,3 @@
1
1
  module Mikado
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -4,7 +4,7 @@ require 'bundler/setup'
4
4
 
5
5
  Bundler.require :test
6
6
 
7
- require 'test/item'
7
+ require File.expand_path("../item", __FILE__)
8
8
 
9
9
  ActiveRecord::Base.establish_connection(
10
10
  :adapter => "sqlite3",
@@ -1,5 +1,5 @@
1
- require 'test/helper'
2
1
  require 'test/unit'
2
+ require File.expand_path("../helper", __FILE__)
3
3
 
4
4
  class ItemTest < Test::Unit::TestCase
5
5
  def setup
@@ -8,7 +8,7 @@ class ItemTest < Test::Unit::TestCase
8
8
 
9
9
  def reload(klass)
10
10
  Object.send(:remove_const, klass.to_s)
11
- load "test/#{klass.to_s.downcase}.rb"
11
+ load File.expand_path("../#{klass.to_s.downcase}.rb", __FILE__)
12
12
  yield
13
13
  end
14
14
 
metadata CHANGED
@@ -1,13 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mikado
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
5
4
  prerelease:
6
- segments:
7
- - 0
8
- - 0
9
- - 3
10
- version: 0.0.3
5
+ version: 0.0.4
11
6
  platform: ruby
12
7
  authors:
13
8
  - Matthias Zirnstein
@@ -15,8 +10,7 @@ autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
12
 
18
- date: 2011-05-04 00:00:00 -07:00
19
- default_executable:
13
+ date: 2011-05-10 00:00:00 Z
20
14
  dependencies: []
21
15
 
22
16
  description: ""
@@ -35,13 +29,13 @@ files:
35
29
  - Rakefile
36
30
  - lib/mikado.rb
37
31
  - lib/mikado/conditional_validation.rb
32
+ - lib/mikado/utility.rb
38
33
  - lib/mikado/version.rb
39
34
  - mikado.gemspec
40
35
  - test/helper.rb
41
36
  - test/item.rb
42
37
  - test/mikado_test.rb
43
38
  - test/prepare.rb
44
- has_rdoc: true
45
39
  homepage: https://github.com/zirni/mikado
46
40
  licenses: []
47
41
 
@@ -55,23 +49,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
55
49
  requirements:
56
50
  - - ">="
57
51
  - !ruby/object:Gem::Version
58
- hash: 3
59
- segments:
60
- - 0
61
52
  version: "0"
62
53
  required_rubygems_version: !ruby/object:Gem::Requirement
63
54
  none: false
64
55
  requirements:
65
56
  - - ">="
66
57
  - !ruby/object:Gem::Version
67
- hash: 3
68
- segments:
69
- - 0
70
58
  version: "0"
71
59
  requirements: []
72
60
 
73
61
  rubyforge_project: mikado
74
- rubygems_version: 1.5.2
62
+ rubygems_version: 1.7.2
75
63
  signing_key:
76
64
  specification_version: 3
77
65
  summary: Wrap validation conditions with a single command