actionfacade 0.0.17.3 → 0.1.0
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/actionfacade.gemspec +1 -0
- data/lib/action_facade/base.rb +29 -4
- data/lib/action_facade/retrieval.rb +12 -0
- data/lib/actionfacade.rb +6 -2
- data/test/base_test.rb +7 -7
- data/test/inheritance_test.rb +11 -11
- data/test/retrieval_test.rb +4 -4
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 99906896fc350593d51d0d42f39e1ee6485da45f1e489978b10576495c51761e
|
4
|
+
data.tar.gz: 36035451577d796e903d9bf827fb83c61330b58e0bf71da07ae66d0c6fabd34d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ce6689c0718cf998e3a635791b7b427653ec64b49bf75db90031ffb4bc09af0cda375cb879bf0437865104a74d193667bf025954ffd774ab442c2ff9abbfdc98
|
7
|
+
data.tar.gz: e5f9b334d397a2690d47d2325b38286a64c82d2d2008a903547b36a7fa655e23d64fb658d1084a49433e4312a684dcaab47f483d8ce3f671de2e1d5b3ca9ccaf
|
data/actionfacade.gemspec
CHANGED
data/lib/action_facade/base.rb
CHANGED
@@ -1,12 +1,37 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module ActionFacade
|
4
|
+
# == Action \Facade \Base
|
5
|
+
#
|
6
|
+
# This is only a base class for extract data from input (payload).
|
7
|
+
# This can be inherited to another class and you can implement
|
8
|
+
# some mothods for obtaining data.
|
9
|
+
# In Ruby on Rails, you can implemented Active Record query methods
|
10
|
+
# to the inherited class.
|
11
|
+
# For example
|
12
|
+
#
|
13
|
+
# class Mypage::IndexFacade < ActionFacade::Base
|
14
|
+
# attr_reader :current_user
|
15
|
+
#
|
16
|
+
# def initialize(payload)
|
17
|
+
# @current_user = payload[:current_user]
|
18
|
+
# end
|
19
|
+
#
|
20
|
+
# def active_users
|
21
|
+
# @active_users ||= User.active.order(login_at: :desc).limit(10)
|
22
|
+
# end
|
23
|
+
#
|
24
|
+
# def messages
|
25
|
+
# @messages ||= current_user.messages.order(created_at: :desc).limit(10)
|
26
|
+
# end
|
27
|
+
# end
|
28
|
+
#
|
4
29
|
class Base
|
5
|
-
attr_reader :
|
30
|
+
attr_reader :payload
|
6
31
|
|
7
|
-
#
|
8
|
-
def initialize(
|
9
|
-
@
|
32
|
+
# Initialize with payload
|
33
|
+
def initialize(payload)
|
34
|
+
@payload = payload
|
10
35
|
end
|
11
36
|
end
|
12
37
|
end
|
@@ -1,7 +1,19 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module ActionFacade
|
4
|
+
# == Action \Facade \Retrieval
|
5
|
+
#
|
6
|
+
# This module provides `retrieve` method to the class which includes the module.
|
7
|
+
# The `retrieve` method can be used for obtaining data from the external facade.
|
8
|
+
# In Ruby on Rails controllers, this module can be used for assing many instance
|
9
|
+
# variables by extracting Active Record queries to the class that is inherited
|
10
|
+
# from ActionFacade::Base.
|
4
11
|
module Retrieval
|
12
|
+
# Retrieve data from `facade`
|
13
|
+
#
|
14
|
+
# `variable_names` are symbols for the method names in the facade and
|
15
|
+
# they will be set as instance variables in the class that
|
16
|
+
# includes the module.
|
5
17
|
def retrieve(facade, *variable_names)
|
6
18
|
variable_names.each do |name|
|
7
19
|
instance_variable_set("@#{name}", facade.send(name.to_sym))
|
data/lib/actionfacade.rb
CHANGED
data/test/base_test.rb
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
require "test/unit"
|
2
|
-
|
2
|
+
require_relative "../lib/actionfacade"
|
3
3
|
|
4
4
|
class BaseTest < Test::Unit::TestCase
|
5
5
|
test ".new does not raise error" do
|
6
|
-
|
7
|
-
assert_nothing_raised { ActionFacade::Base.new(
|
6
|
+
payload = {}
|
7
|
+
assert_nothing_raised { ActionFacade::Base.new(payload) }
|
8
8
|
end
|
9
9
|
|
10
|
-
test "#
|
11
|
-
|
12
|
-
facade = ActionFacade::Base.new(
|
13
|
-
assert_equal(facade.
|
10
|
+
test "#payload returns original payload object" do
|
11
|
+
payload = {}
|
12
|
+
facade = ActionFacade::Base.new(payload)
|
13
|
+
assert_equal(facade.payload, payload)
|
14
14
|
end
|
15
15
|
end
|
data/test/inheritance_test.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
require "test/unit"
|
2
|
-
|
2
|
+
require_relative "../lib/actionfacade"
|
3
3
|
|
4
4
|
class UserFacade < ActionFacade::Base
|
5
5
|
USER_DATA = [{ id: 1, name: "john" }, { id: 2, name: "taro" }]
|
@@ -15,25 +15,25 @@ end
|
|
15
15
|
|
16
16
|
class InheritanceTest < Test::Unit::TestCase
|
17
17
|
test ".new does not raise error" do
|
18
|
-
|
19
|
-
assert_nothing_raised { UserFacade.new(
|
18
|
+
payload = {}
|
19
|
+
assert_nothing_raised { UserFacade.new(payload) }
|
20
20
|
end
|
21
21
|
|
22
|
-
test "#
|
23
|
-
|
24
|
-
facade = UserFacade.new(
|
25
|
-
assert_equal(facade.
|
22
|
+
test "#payload returns user object" do
|
23
|
+
payload = {}
|
24
|
+
facade = UserFacade.new(payload)
|
25
|
+
assert_equal(facade.payload, payload)
|
26
26
|
end
|
27
27
|
|
28
28
|
test "#all returns all data" do
|
29
|
-
|
30
|
-
facade = UserFacade.new(
|
29
|
+
payload = {}
|
30
|
+
facade = UserFacade.new(payload)
|
31
31
|
assert_equal(facade.all, [{ id: 1, name: "john" }, { id: 2, name: "taro" }])
|
32
32
|
end
|
33
33
|
|
34
34
|
test "#taro returns taro's data" do
|
35
|
-
|
36
|
-
facade = UserFacade.new(
|
35
|
+
payload = {}
|
36
|
+
facade = UserFacade.new(payload)
|
37
37
|
assert_equal(facade.taro, { id: 2, name: "taro" })
|
38
38
|
end
|
39
39
|
end
|
data/test/retrieval_test.rb
CHANGED
@@ -2,9 +2,9 @@ require "test/unit"
|
|
2
2
|
require_relative "../lib/action_facade/base.rb"
|
3
3
|
require_relative "../lib/action_facade/retrieval.rb"
|
4
4
|
|
5
|
-
|
6
|
-
USER_DATA = [{ id: 1, name: "john" }]
|
5
|
+
USER_DATA = [{ id: 1, name: "john" }]
|
7
6
|
|
7
|
+
class UserFacade < ActionFacade::Base
|
8
8
|
def john
|
9
9
|
USER_DATA.find { |user| user[:name] == "john" }
|
10
10
|
end
|
@@ -16,8 +16,8 @@ class UsersController
|
|
16
16
|
attr_reader :john
|
17
17
|
|
18
18
|
def show
|
19
|
-
|
20
|
-
facade = UserFacade.new(
|
19
|
+
payload = {}
|
20
|
+
facade = UserFacade.new(payload)
|
21
21
|
retrieve(facade, :john)
|
22
22
|
end
|
23
23
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: actionfacade
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryo Hashimoto
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-01-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: test-unit
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.3'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.3'
|
41
55
|
description: Action Facade provides a simple interface for data required by view /
|
42
56
|
controller.
|
43
57
|
email: ryohashimoto@gmail.com
|