fanli 0.2.0 → 0.2.1
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.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/fanli/base.rb +18 -6
- data/lib/fanli/event.rb +13 -0
- data/lib/fanli/version.rb +1 -1
- data/lib/fanli.rb +9 -3
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6f47451e553d268417abf3904c2754baa0665b50
|
4
|
+
data.tar.gz: 958a0d2df207496be33d4536c21e22cdaf6e048b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
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
|
8
|
-
|
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
|
13
|
-
|
14
|
-
|
15
|
-
|
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
|
data/lib/fanli/event.rb
ADDED
data/lib/fanli/version.rb
CHANGED
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,
|
36
|
+
def self.apply_callback(callback, data, objs)
|
36
37
|
return if objs.nil?
|
37
38
|
objs.map do |obj|
|
38
|
-
|
39
|
-
|
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.
|
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:
|