fanli 0.2.0 → 0.2.1

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: c21e9111e908bd2f7678fccfce79032590b94757
4
- data.tar.gz: 758209c675394a3154dc12ef00340116f2465904
3
+ metadata.gz: 6f47451e553d268417abf3904c2754baa0665b50
4
+ data.tar.gz: 958a0d2df207496be33d4536c21e22cdaf6e048b
5
5
  SHA512:
6
- metadata.gz: 8a57f073dc1505d9fa828e207ab54fae8deb4d190ef45201d9d36da1f5fc967e79abb4ea7ae6e8b3675be241372422c3b7bd2511c5a1eb88bd78748a574e7c1a
7
- data.tar.gz: 03a0a82fcade8bec83dc58df943bc4c92536515b938de3de892d6e7b6d52041816fb53a22b8d747bf614954b6bf95f13d78b6a794f836d8387a260dc6ded32f2
6
+ metadata.gz: 8d1f635cd1c9659d506bed9735ac009af0053eb0f8f1aca003cf53af3e8ca14b4e2f6c33bfd4103799dd3b77a1777a9711ef2948144a73e1aa9790c345734d68
7
+ data.tar.gz: 5a89106460e186b72844c83677a32aaa46db5d86f9cdac02e101925fabdaca58c69c912bc0576e49e74845e6c9aa153c1cc55f94ba783a3564304f4d6de07641
data/README.md CHANGED
@@ -126,7 +126,7 @@ To solve this problem and prevent messy code, you should write code in "The Fanl
126
126
  # app/controllers/users_controller.rb
127
127
  class UsersController < ApplicationController
128
128
  def create
129
- CreateUser.with(params.require(:user).permit(:name, :email))
129
+ CreateUser.exec(params.require(:user).permit(:name, :email))
130
130
  end
131
131
  end
132
132
  ```
data/lib/fanli/base.rb CHANGED
@@ -1,18 +1,30 @@
1
1
  module Fanli
2
+ # Base class to inherit
2
3
  class Base
3
4
  def self.inherited(sub)
4
5
  sub.extend(ClassMethods)
5
6
  end
6
7
 
7
- def call(*_args)
8
- throw(:please_create_your_own_call_method)
8
+ def initialize(*args)
9
+ @args = args
9
10
  end
10
11
 
12
+ def perform
13
+ throw(:please_create_your_own_perform_method)
14
+ end
15
+
16
+ # Class Methods
11
17
  module ClassMethods
12
- def with(opts)
13
- obj = new
14
- obj.call(opts)
15
- Fanli.trigger(snikize(name), with: opts)
18
+ def exec(*args)
19
+ new(args).tap do |business|
20
+ Fanli.trigger(
21
+ snikize(name),
22
+ with: Fanli::Event.new(
23
+ args: args,
24
+ result: business.perform
25
+ )
26
+ )
27
+ end
16
28
  end
17
29
 
18
30
  private
@@ -0,0 +1,13 @@
1
+ module Fanli
2
+ # The event object
3
+ class Event
4
+ def initialize(args:, result:)
5
+ @args = args
6
+ @result = result
7
+ end
8
+
9
+ def args(index)
10
+ @args[index]
11
+ end
12
+ end
13
+ end
data/lib/fanli/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Fanli
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
data/lib/fanli.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'fanli/version'
2
2
  require 'fanli/base'
3
+ require 'fanli/event'
3
4
 
4
5
  # Fanli
5
6
  module Fanli
@@ -32,11 +33,16 @@ module Fanli
32
33
  end
33
34
  end
34
35
 
35
- def self.apply_callback(callback, args, objs)
36
+ def self.apply_callback(callback, data, objs)
36
37
  return if objs.nil?
37
38
  objs.map do |obj|
38
- obj.send(callback, args) if obj.respond_to?(callback)
39
- obj.call(args) if obj.respond_to?(:call)
39
+ if obj.respond_to?(callback)
40
+ obj.send(callback, data)
41
+ elsif obj.respond_to?(:call)
42
+ obj.call(data)
43
+ else
44
+ next
45
+ end
40
46
  end
41
47
  end
42
48
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fanli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Zhang
@@ -87,6 +87,7 @@ files:
87
87
  - fanli.gemspec
88
88
  - lib/fanli.rb
89
89
  - lib/fanli/base.rb
90
+ - lib/fanli/event.rb
90
91
  - lib/fanli/version.rb
91
92
  homepage: http://github.com/daqing/fanli
92
93
  licenses: