aristotle 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: beb607b0e69afe31331e87b364ebe0596d446b6e
4
- data.tar.gz: c1accdb3321d49082eaff261bda5f77995f54f46
3
+ metadata.gz: 6d2a18bca70211e50817929721c99732312ce148
4
+ data.tar.gz: 809d4125036f6a5aae4fdb8339767ff2121786ca
5
5
  SHA512:
6
- metadata.gz: 30cebb52fa456e598a643fae0c691c070b2ad886e703e28e2a8a637926d71bd6a641947b74bb957edf631b920a99eab61bf267fbae20c81a0122fc442406d5d1
7
- data.tar.gz: a93c35022426c2e8bd9dcbdeb51d42120ee0520875191760dba25204a49f98166ce2a78e500b099891f1ac67c18a5a8ea844db52def1dfdc3611de4e60a71821
6
+ metadata.gz: 2aaba2c0571dfee8a2fffbb8b471d19e29b295666ce18da870373b4ef889a5c48c605e442ff664a09b193a9d647e5fb4356bcd8a8f786d8f86c0b0e4955f066e
7
+ data.tar.gz: 463a7e3e4cb6c7640c9663e247ec23480e7fc1ce17d8f74b71c90f1350c946fb189901a4f0f1831487ce255bca05dc9d99d623e04a9bf099b6ce5f6886c8c6fa
@@ -16,25 +16,25 @@ module Aristotle
16
16
 
17
17
  def self.commands(logic_method = nil)
18
18
  load_commands
19
- logic_method.nil? ? @@commands : (@@commands[logic_method] || [])
19
+ logic_method.nil? ? @commands : (@commands[logic_method] || [])
20
20
  end
21
21
 
22
22
  # called when class is loaded
23
23
  def self.condition(expression, &block)
24
- @@conditions ||= {}
25
- @@conditions[expression] = block
24
+ @conditions ||= {}
25
+ @conditions[expression] = block
26
26
  end
27
27
 
28
28
  # called when class is loaded
29
29
  def self.action(expression, &block)
30
- @@actions ||= {}
31
- @@actions[expression] = block
30
+ @actions ||= {}
31
+ @actions[expression] = block
32
32
  end
33
33
 
34
34
  def self.load_commands
35
- @@commands ||= {}
35
+ @commands ||= {}
36
36
 
37
- return if @@commands != {}
37
+ return if @commands != {}
38
38
 
39
39
  filename = "app/logic/#{logic_name}.logic"
40
40
  logic_data = File.read(filename)
@@ -46,8 +46,8 @@ module Aristotle
46
46
  if line.start_with? ' '
47
47
  raise "#{filename} is broken!" if command.nil?
48
48
 
49
- @@commands[command] ||= []
50
- @@commands[command] << Aristotle::Command.new(line.strip, @@conditions, @@actions)
49
+ @commands[command] ||= []
50
+ @commands[command] << Aristotle::Command.new(line.strip, @conditions || {}, @actions || {})
51
51
  else
52
52
  command = line
53
53
  end
@@ -1,29 +1,60 @@
1
1
  module Aristotle
2
2
  class Utility
3
3
  def self.check_all
4
- logic_objects.each_with_index do |logic_class, i|
5
- puts "Checking #{logic_class}"
6
- is_everything_covered_for? logic_class
7
- puts if i > 0
4
+ logic_objects.each do |logic_object|
5
+ puts "Checking #{logic_object[:class_name]}"
6
+ is_everything_covered_for? logic_object
7
+ puts
8
8
  end
9
9
  end
10
10
 
11
11
  protected
12
12
 
13
13
  def self.logic_objects
14
- init_logic_objects unless @logic_objects_initialized
14
+ init_logic_objects if @logic_objects.nil? || @logic_objects == {}
15
15
 
16
- ObjectSpace.each_object(Class).select { |klass| klass < Aristotle::Logic }
16
+ @logic_objects
17
17
  end
18
18
 
19
19
  def self.init_logic_objects
20
- Dir[%w(app logic *.rb).join(File::SEPARATOR)].each do |file|
21
- require Dir.pwd + File::SEPARATOR + file
20
+ @logic_objects ||= []
21
+
22
+ Dir[%w(app logic *.logic).join(File::SEPARATOR)].each do |file|
23
+ logic_name = file.split(File::SEPARATOR).last.split('.logic').first
24
+ folder = %W{#{Dir.pwd} app logic}.join(File::SEPARATOR)
25
+ class_name = logic_name.split('_').map(&:capitalize).join('') + 'Logic'
26
+
27
+ logic_object = {
28
+ logic_file: folder + File::SEPARATOR + "#{logic_name}.logic",
29
+ class_file: folder + File::SEPARATOR + "#{logic_name}_logic.rb",
30
+ relative_class_file: %W(app logic #{logic_name}_logic.rb).join(File::SEPARATOR),
31
+ class_name: class_name
32
+ }
33
+
34
+ begin
35
+ require logic_object[:class_file]
36
+ logic_object[:logic_class] = Object.const_get(class_name)
37
+ rescue LoadError => e
38
+ logic_object[:logic_class] = nil
39
+ rescue
40
+ logic_object[:logic_class] = nil
41
+ end
42
+
43
+ @logic_objects << logic_object
22
44
  end
23
- @logic_objects_initialized = true
24
45
  end
25
46
 
26
- def self.is_everything_covered_for?(logic_class)
47
+ def self.is_everything_covered_for?(logic_object)
48
+ logic_class = logic_object[:logic_class]
49
+
50
+ if logic_class.nil?
51
+ puts "--> Create file #{logic_object[:relative_class_file]} with the following contents:"
52
+ puts "class #{logic_object[:class_name]} < Aristotle::Logic"
53
+ puts ' # ...'
54
+ puts 'end'
55
+ return
56
+ end
57
+
27
58
  not_covered = {}
28
59
  logic_class.commands.each do |logic_method, commands|
29
60
  commands.each do |command|
@@ -40,7 +71,8 @@ module Aristotle
40
71
 
41
72
  if not_covered != {}
42
73
  not_covered.each do |request_method, data|
43
- puts "\nclass #{self.to_s} < Aristotle::Logic"
74
+ puts "\n# #{logic_object[:relative_class_file]}"
75
+ puts "class #{logic_object[:class_name]} < Aristotle::Logic"
44
76
  puts " # #{request_method}:\n"
45
77
  data[:actions].each do |action|
46
78
  puts " action /#{action}/ do |#{logic_class.logic_name}|\n\n end\n\n"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aristotle
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marius Andra
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-22 00:00:00.000000000 Z
11
+ date: 2014-11-25 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Ruby business logic engine, inspired by Cucumber
14
14
  email: marius@apprentus.com