onuro 0.1.2 → 0.1.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
  SHA256:
3
- metadata.gz: 0b8f298894039efad8040411f7f20ef9520904d86ba94e2a2e81affec3e3e42e
4
- data.tar.gz: 69feab312564ca16fa4bcd2da211cf40c67e961379a744857c920bad0d761bb7
3
+ metadata.gz: ba55460305728147a6a6902162062d320bb2c8f3324b7001b2177b46ef5d297f
4
+ data.tar.gz: 426b556b04838c980ee44fee95210322ed89eeef0e522de578e3358183b0e88d
5
5
  SHA512:
6
- metadata.gz: 342d089f5b6ea8180887d006e37fb3a3e13951483688774b46288319ea68e777230dee9f26e432f47611a72bd1fc24330d99858318d27afa47f70977b951e441
7
- data.tar.gz: dddd4518bbf349f4b2ba1700936d6eee919f320e21d335e8fde0c365c360cbe1e6151169fc6b04ba0d8618728d3eaa6c6f42ba8045fbd6113eafd2981d5cf1b5
6
+ metadata.gz: 8e74ec30d7458cfb9f27d451181a1abd5272e4e7c0f8e715a1e080fd672f0d22b773cd48a36cca5b1047af3a0400b2b6b8eea5cbe7cbb572c32ebeb18c77cb45
7
+ data.tar.gz: 1c8c9b00aabdb5138095427d48eee6c7965fd69a17da7d52d616f6d758f3a1f3eafd726f146d9121364e9e354803b2e197d20c8ccabf7b251ee1643ec27b782f
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- onuro (0.1.2)
4
+ onuro (0.1.3)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -22,6 +22,43 @@ Or install it yourself as:
22
22
 
23
23
  ## Usage
24
24
 
25
+ The easiest way to load Event + Rules configuration in the **Engine** is using the configuration blocks. Its important to mention these global pre-configured events, would be changed when in runt-time an **engine instance** is begin fetched with new events.
26
+
27
+ ```ruby
28
+ class Rule1 < Onuro::BaseRule; end
29
+ class Rule2 < Onuro::BaseRule; end
30
+ class Rule3 < Onuro::BaseRule; end
31
+ class MyCustomEventStrategy < Onuro::DefaultEventStrategy; end
32
+
33
+
34
+ Onuro::Engine.configure do |config|
35
+ config.add_event(:event_one) do |event|
36
+ event.add_ruleset_stage [
37
+ Onuro::RuleStage.new(rule: Rule1, enabled: true, order: 1),
38
+ Onuro::RuleStage.new(rule: Rule3, enabled: true, order: 2)
39
+ ]
40
+ event.add_event_strategy(MyCustomEventStrategy.new)
41
+ event.exec_order(:desc)
42
+ event.ignore_diseabled
43
+ end
44
+
45
+ config.add_event(:event_two) do |event|
46
+ event.add_ruleset_stage [
47
+ Onuro::RuleStage.new(rule: Rule1, enabled: true, order: 1),
48
+ Onuro::RuleStage.new(rule: Rule2, enabled: true, order: 2)
49
+ ]
50
+ end
51
+
52
+ config.add_event(:event_three) do |event|
53
+ event.add_ruleset_stage [Onuro::RuleStage.new(rule: Rule1, enabled: true, order: 1)]
54
+ end
55
+
56
+ config.add_event(:event_four) do |event|
57
+ event.add_rule_stage Onuro::RuleStage.default_ruleset_stage_factory([Rule1, Rule2, Rule3])
58
+ end
59
+ end
60
+ ```
61
+
25
62
  ### Engine
26
63
 
27
64
  ### Rule
@@ -40,12 +77,12 @@ engine.execute(:my_event)
40
77
 
41
78
  ### Event Builder
42
79
 
43
- An easier way to create an event, is using the **EventBuilder*** class based on the *builder pattern*. This gives a lot of flexibility when you are creating the events and avoid having a lot or parameters in the constructor and assembling all the event internals, and easy to to be plugged in you **Engine** class instance.
80
+ An easier way to create an event, is using the **EventBuilder** class based on the *builder pattern*. This gives a lot of flexibility when you are creating the events and avoid having a lot or parameters in the constructor and assembling all the event internals, and easy to to be plugged in you **Engine** class instance.
44
81
 
45
82
  ```ruby
46
83
  event = EventBuilder.build(:test_ruleset) do |builder|
47
84
  builder.add_ruleset_stage([rule1, rule2, rule3])
48
- builder.add_event_strategy(MyCustomEventStrategy)
85
+ builder.add_event_strategy(MyCustomEventStrategy.new)
49
86
  builder.exec_order(:desc)
50
87
  buidler.ignore_diseabled
51
88
  end
data/lib/onuro/engine.rb CHANGED
@@ -6,8 +6,46 @@ module Onuro
6
6
 
7
7
  attr_accessor :events
8
8
 
9
+ class << self
10
+ # Setter for shared global objects
11
+ attr_writer :configuration
12
+ end
13
+
14
+ # Returns the global [EngineConfiguration](Onuro/EngineConfiguration) object. While
15
+ # you _can_ use this method to access the configuration, the more common
16
+ # convention is to use [Onuro::Engine.configure](Onuro::Engine#configure-class_method).
17
+ #
18
+ # @example
19
+ # Onuro::Engine.configuration.tbd = 1234
20
+ # @see Onuro::Engine.configure
21
+ # @see Onuro::EngineConfiguration
22
+ def self.configuration
23
+ @configuration ||= Onuro::EngineConfiguration.new
24
+ end
25
+
26
+ # Users must invoke this if they want to have the configuration reset when
27
+ # they use the runner multiple times within the same process. Users must deal
28
+ # themselves with re-configuration of Onuro::Engine before run.
29
+ def self.reset
30
+ @configuration = nil
31
+ end
32
+
33
+ # Yields the global configuration to a block.
34
+ # @yield [EngineConfiguration] global configuration
35
+ #
36
+ # @example
37
+ # Onuro::Engine.configure do |config|
38
+ # config.events 'documentation'
39
+ # end
40
+ # @see Onuro::EngineConfiguration
41
+ def self.configure
42
+ yield configuration if block_given?
43
+ end
44
+
9
45
  def initialize
10
- self.events = Hash.new(0)
46
+ # Loading events from the global configuration, if we have it
47
+ # We need to clone, otherwise will get the smae obejct_id reference
48
+ self.events = Engine.configuration.events.clone
11
49
  end
12
50
 
13
51
  def add_event(event)
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Onuro
4
+ class EngineConfiguration
5
+ attr_reader :events
6
+
7
+ def initialize
8
+ @events = Hash.new(0)
9
+ end
10
+
11
+ def add_event(event_name)
12
+ event = EventBuilder.build(event_name)
13
+ events[event.name] = event
14
+ end
15
+ end
16
+ end
@@ -32,7 +32,7 @@ module Onuro
32
32
 
33
33
  def self.build(name)
34
34
  builder = new(name)
35
- yield builder
35
+ yield builder if block_given?
36
36
  builder.event
37
37
  end
38
38
  end
@@ -9,5 +9,15 @@ module Onuro
9
9
  @enabled = enabled
10
10
  @order = order
11
11
  end
12
+
13
+ def self.default_ruleset_stage_factory(rules)
14
+ ruleset_stage = []
15
+ order = 1
16
+ rules.each do |rule|
17
+ ruleset_stage << RuleStage.new(rule: rule, enabled: true, order: order)
18
+ order += 1
19
+ end
20
+ ruleset_stage
21
+ end
12
22
  end
13
23
  end
data/lib/onuro/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Onuro
4
- VERSION = '0.1.2'
4
+ VERSION = '0.1.3'
5
5
  end
data/lib/onuro.rb CHANGED
@@ -3,6 +3,7 @@
3
3
  require 'onuro/version'
4
4
  require 'onuro/execution_result'
5
5
  require 'onuro/logging'
6
+ require 'onuro/engine_configuration'
6
7
  require 'onuro/engine'
7
8
  require 'onuro/default_event_strategy'
8
9
  require 'onuro/event_builder'
@@ -10,6 +11,7 @@ require 'onuro/event'
10
11
  require 'onuro/base_rule'
11
12
  require 'onuro/rule_stage'
12
13
 
14
+ # Namespace for all Onuro code.
13
15
  module Onuro
14
16
  class Error < StandardError; end
15
17
  class InvalidEventNameException < StandardError; end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: onuro
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rodrigo Reyes
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-07-14 00:00:00.000000000 Z
11
+ date: 2019-07-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -159,6 +159,7 @@ files:
159
159
  - lib/onuro/base_rule.rb
160
160
  - lib/onuro/default_event_strategy.rb
161
161
  - lib/onuro/engine.rb
162
+ - lib/onuro/engine_configuration.rb
162
163
  - lib/onuro/event.rb
163
164
  - lib/onuro/event_builder.rb
164
165
  - lib/onuro/execution_result.rb