Conditionator 0.1 → 0.2

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/lib/conditionator.rb CHANGED
@@ -1,17 +1,13 @@
1
1
  require 'conditionator/hooks'
2
2
 
3
- #Extends all objects to check for conditions
4
- class Object
5
- include Conditionator
6
-
7
- class << self
8
- alias_method :old_new, :new
9
-
10
- def new *args
11
- o = old_new(*args)
12
- o.load_conditions
13
- o
3
+ #Main module, including this module in your class will attach it the methods
4
+ module Conditionator
5
+ VERSION = 0.2
6
+
7
+ def self.included base
8
+ base.send :include, ConditionatorHooks
9
+ def base.new(*)
10
+ super.tap(&:load_conditions)
14
11
  end
15
12
  end
16
-
17
13
  end
@@ -1,13 +1,13 @@
1
- module Conditionator
1
+ module ConditionatorHooks
2
2
 
3
- class PreconditionsNotMet < Exception
3
+ class PreconditionsNotMet < StandardError
4
4
  end
5
5
 
6
- private
6
+ private
7
7
  def conditions type
8
8
  conds = {}
9
9
  data = self.class.data
10
-
10
+
11
11
  data[self.class.name].each do |method, filter|
12
12
  if filter.key? type
13
13
  conds[method] = [] if conds[method].nil?
@@ -21,7 +21,7 @@ private
21
21
  base.send :extend, ClassLevelConditionator
22
22
  end
23
23
 
24
- public
24
+ public
25
25
  #Returns a list of all preconditions, grouped by the method they're a precondition to.
26
26
  def preconditions
27
27
  conditions :pre
@@ -36,31 +36,37 @@ public
36
36
 
37
37
  _data = self.class.data
38
38
  _data[self.class.name] = {} if _data[self.class.name].nil?
39
-
39
+
40
40
  _data[self.class.name].each { |method, type|
41
41
  type.each { |_when, data|
42
-
42
+
43
43
  arr_methods = data[:methods]
44
-
44
+
45
45
  if !self.respond_to? "#{method}_with_#{_when}_cond".to_sym
46
46
  self.class.send :define_method, "#{method}_with_#{_when}_cond".to_sym do |*p|
47
47
  if(_when == :pre)
48
48
  returns = arr_methods.collect do |m|
49
- self.send(m) ? true : false
49
+ self.send(m, *p) ? true : false
50
50
  end
51
51
  returns.uniq!
52
- if returns.length == 1 and returns.include? true
53
- data[:block].call(self) if !data[:block].nil?
54
- else
52
+
53
+ if returns.include? false
55
54
  raise PreconditionsNotMet
56
55
  end
56
+ #if returns.length == 1 and returns.include? true
57
+ #data[:block].call(self) if !data[:block].nil?
58
+ #else
59
+ #raise PreconditionsNotMet
60
+ #end
57
61
  end
58
- self.send "#{method}_without_#{_when}_cond".to_sym, *p
62
+ ret_value = self.send "#{method}_without_#{_when}_cond".to_sym, *p
59
63
  if(_when == :post)
60
- arr_methods.each do |m| self.send m end
61
- data[:block].call(self) if !data[:block].nil?
64
+ arr_methods.each do |m|
65
+ self.send m, *p, ret_value
66
+ end
67
+ #data[:block].call(self) if !data[:block].nil?
62
68
  end
63
-
69
+ return ret_value
64
70
  end
65
71
  self.class.send :alias_method, "#{method}_without_#{_when}_cond".to_sym, method
66
72
  self.class.send :alias_method, method, "#{method}_with_#{_when}_cond".to_sym
@@ -121,9 +127,5 @@ public
121
127
  add_condition_for :post, method_name, conditions
122
128
  end
123
129
  end
124
-
125
-
126
130
  end
127
-
128
-
129
131
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: Conditionator
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.1'
4
+ version: '0.2'
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: 2012-05-15 00:00:00.000000000Z
12
+ date: 2012-05-17 00:00:00.000000000Z
13
13
  dependencies: []
14
14
  description: This gem allows you to set pre and post conditions to your methods, in
15
15
  order to assure their successfull excecution
@@ -20,7 +20,7 @@ extra_rdoc_files: []
20
20
  files:
21
21
  - lib/conditionator.rb
22
22
  - lib/conditionator/hooks.rb
23
- homepage:
23
+ homepage: https://github.com/deleteman/conditionatorr
24
24
  licenses: []
25
25
  post_install_message:
26
26
  rdoc_options: []
@@ -31,7 +31,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
31
31
  requirements:
32
32
  - - ! '>='
33
33
  - !ruby/object:Gem::Version
34
- version: '0'
34
+ version: 1.9.2
35
35
  required_rubygems_version: !ruby/object:Gem::Requirement
36
36
  none: false
37
37
  requirements: