lightrails 0.0.5 → 0.0.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a0f59fc251ed38f0401596419fb3b9b21f896a059560a0d37f6a669f060d7d0b
4
- data.tar.gz: b6b52941c6637741b8f11d83ff9b79806eb452f44eafc1ac5ab095ad4a60419a
3
+ metadata.gz: f9498da26782c4d6ecffcff083be4c80f71c0b252c4640ffb4aac5eaf5c8d818
4
+ data.tar.gz: 48a3522f9d95d0702a11b0b6039ceb97bbbf1e337b1b9b33b8a55593e7b74087
5
5
  SHA512:
6
- metadata.gz: 33538eab110372881f27898622f098d3c576aa7e9a5dd422fe39e33eef7196a4a09b5565dca7e2b4561b87e31eefe71ecdb825a3d08955f00b2800dc7375a530
7
- data.tar.gz: d83862f53ca925a90ce7d26c61a9e6f2ffc9b2c1822d7cd288b930d6095fa056a9c76a583c12a856ee2dbd4a18f355de58bd64ffc1db82c5b6d3879ad122a397
6
+ metadata.gz: b9af6ba83d01260fd00412912f72dffbc60ded387982e17967680e76fede3a0d719c6e1ff1e9d7aac37e9aee8c22270ca0b97f0c67c38215eabedce3f9067cd1
7
+ data.tar.gz: db1eebaba7422bc38d0e698f184a252f37598adf09f58cd9064426913333b3911b6f0854cf2b3c14bfbc23b0ee9eb89549af695883f9c248f6611ca698028190
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2018 Ryo Hashimoto
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md CHANGED
@@ -1,6 +1,56 @@
1
1
  # Lightrails
2
2
 
3
- Utility library for Ruby on Rails
3
+ Lightrails is a utility library including Action Interactor, Active Representer etc.
4
+ It aims to provide more modular layers for Ruby on Rails applications.
5
+
6
+ ## Getting Started
7
+
8
+ Add `lightrails` to your Rails project's Gemfile and `bundle install`.
9
+
10
+ ```ruby
11
+ gem "lightrails"
12
+ ```
13
+
14
+ Run generators.
15
+
16
+ ```
17
+ $ bin/rails generate action_facade:install
18
+ $ bin/rails generate action_interactor:install
19
+ $ bin/rails generate active_representer:install
20
+ ```
21
+
22
+ ## Action Facade
23
+
24
+ Add a simple interface for obtaining multiple data in controller.
25
+
26
+ ```ruby
27
+ class Mypage::IndexFacade < ApplicationFacade
28
+ attr_reader :current_user
29
+
30
+ def initialize(params)
31
+ @current_user = params[:current_user]
32
+ end
33
+
34
+ def active_user
35
+ @all_user ||= User.active.order(login_at: :desc).limit(10)
36
+ end
37
+
38
+ def messages
39
+ @messages ||= current_user.messages.order(created_at: :desc).limit(10)
40
+ end
41
+ end
42
+
43
+ # in MypageController
44
+ def index
45
+ @facade = Mypage::IndexFacade.new(current_user: current_user)
46
+ end
47
+ ```
48
+
49
+ To create an facade, you can use the generator.
50
+
51
+ ```
52
+ $ bin/rails generate facade mypage/index
53
+ ```
4
54
 
5
55
  ## Action Interactor
6
56
 
@@ -15,7 +65,7 @@ class User
15
65
  end
16
66
  end
17
67
 
18
- class RegistrationInteractor < ActionInteractor::Base
68
+ class RegistrationInteractor < ApplicationInteractor
19
69
  def execute
20
70
  return unless params[:name]
21
71
  add_result(:user, User.new(name: params[:name]))
@@ -24,25 +74,41 @@ class RegistrationInteractor < ActionInteractor::Base
24
74
  end
25
75
  end
26
76
 
27
- interactor = RegistrationInteractor.execute(params)
77
+ interactor = RegistrationInteractor.execute(name: "John")
28
78
  interactor.success? # => true
29
79
  interactor.completed? # => true
30
80
  user = interactor.result[:user]
31
81
  user.name # => 'John'
32
82
  ```
33
83
 
84
+ To create an interactor, you can use the generator.
85
+
86
+ ```
87
+ $ bin/rails generate interactor registration
88
+ ```
89
+
34
90
  ## Active Representer
35
91
 
36
92
  Add an API model layer to your Rails application.
37
93
 
38
94
  ```ruby
39
- class UserRepresenter < ActiveRepresenter::Base
95
+ class UserRepresenter < ApplicationRepresenter
40
96
  def full_name
41
97
  "#{first_name} #{last_name}"
42
98
  end
43
99
  end
44
100
 
45
- user = OpenStruct.new(first_name: 'John', last_name: 'Appleseed')
101
+ user = OpenStruct.new(first_name: "John", last_name: "Appleseed")
46
102
  representer = UserRepresenter.new(user)
47
103
  representer.full_name # => 'John Appleseed'
48
104
  ```
105
+
106
+ To create a representer, you can use the generator.
107
+
108
+ ```
109
+ $ bin/rails generate representer user
110
+ ```
111
+
112
+ ## License
113
+
114
+ MIT License. Copyright 2018 Ryo Hashimoto.
@@ -0,0 +1 @@
1
+ 2018-10-06
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.6
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+ module ActionFacade
3
+ module Generators
4
+ class InstallGenerator < ::Rails::Generators::Base
5
+ source_root File.expand_path("../templates", __FILE__)
6
+
7
+ def copy_application_facade_file
8
+ template "application_facade.rb", File.join("app/facades/application_facade.rb")
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,2 @@
1
+ class ApplicationFacade < ActionFacade::Base
2
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+ module ActionInteractor
3
+ module Generators
4
+ class InstallGenerator < ::Rails::Generators::Base
5
+ source_root File.expand_path("../templates", __FILE__)
6
+
7
+ def copy_application_interactor_file
8
+ template "application_interactor.rb", File.join("app/interactors/application_interactor.rb")
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,2 @@
1
+ class ApplicationInteractor < ActionInteractor::Base
2
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+ module ActiveRepresenter
3
+ module Generators
4
+ class InstallGenerator < Rails::Generators::Base
5
+ source_root File.expand_path("../templates", __FILE__)
6
+
7
+ def copy_application_representer_file
8
+ template "application_representer.rb", File.join("app/representers/application_representer.rb")
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,2 @@
1
+ class ApplicationRepresenter < ActiveRepresenter::Base
2
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+ module Rails
3
+ module Generators
4
+ class FacadeGenerator < ::Rails::Generators::NamedBase
5
+ source_root File.expand_path("../templates", __FILE__)
6
+
7
+ def copy_facade_file
8
+ template "facade.tt", File.join("app/facades", class_path, "#{file_name}_facade.rb")
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+ module Rails
3
+ module Generators
4
+ class InteractorGenerator < ::Rails::Generators::NamedBase
5
+ source_root File.expand_path("../templates", __FILE__)
6
+
7
+ def copy_interactor_file
8
+ template "interactor.tt", File.join("app/interactors", class_path, "#{file_name}_interactor.rb")
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+ module Rails
3
+ module Generators
4
+ class RepresenterGenerator < ::Rails::Generators::NamedBase
5
+ source_root File.expand_path("../templates", __FILE__)
6
+
7
+ def copy_representer_file
8
+ template "representer.tt", File.join("app/representers", class_path, "#{file_name}_representer.rb")
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,4 @@
1
+ <% module_namespacing do -%>
2
+ class <%= class_name %>Facade < ApplicationFacade
3
+ end
4
+ <% end -%>
@@ -0,0 +1,7 @@
1
+ <% module_namespacing do -%>
2
+ class <%= class_name %>Interactor < ApplicationInteractor
3
+ def execute
4
+ super
5
+ end
6
+ end
7
+ <% end -%>
@@ -0,0 +1,4 @@
1
+ <% module_namespacing do -%>
2
+ class <%= class_name %>Representer < ApplicationRepresenter
3
+ end
4
+ <% end -%>
@@ -0,0 +1,3 @@
1
+ require 'actionfacade'
2
+ require 'actioninteractor'
3
+ require 'activerepresenter'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lightrails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryo Hashimoto
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-10-05 00:00:00.000000000 Z
11
+ date: 2018-10-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -24,34 +24,48 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '5.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: actionfacade
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '='
32
+ - !ruby/object:Gem::Version
33
+ version: 0.0.6
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '='
39
+ - !ruby/object:Gem::Version
40
+ version: 0.0.6
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: actioninteractor
29
43
  requirement: !ruby/object:Gem::Requirement
30
44
  requirements:
31
45
  - - '='
32
46
  - !ruby/object:Gem::Version
33
- version: 0.0.5
47
+ version: 0.0.6
34
48
  type: :runtime
35
49
  prerelease: false
36
50
  version_requirements: !ruby/object:Gem::Requirement
37
51
  requirements:
38
52
  - - '='
39
53
  - !ruby/object:Gem::Version
40
- version: 0.0.5
54
+ version: 0.0.6
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: activerepresenter
43
57
  requirement: !ruby/object:Gem::Requirement
44
58
  requirements:
45
59
  - - '='
46
60
  - !ruby/object:Gem::Version
47
- version: 0.0.5
61
+ version: 0.0.6
48
62
  type: :runtime
49
63
  prerelease: false
50
64
  version_requirements: !ruby/object:Gem::Requirement
51
65
  requirements:
52
66
  - - '='
53
67
  - !ruby/object:Gem::Version
54
- version: 0.0.5
68
+ version: 0.0.6
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: bundler
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -66,14 +80,31 @@ dependencies:
66
80
  - - ">="
67
81
  - !ruby/object:Gem::Version
68
82
  version: 1.3.0
69
- description: Lightrails is a utility library including ActionInteractor, ActiveRepresenter
70
- etc. for Ruby on Rails.
83
+ description: Lightrails is a utility library including Action Facade, Action Interactor,
84
+ Active Representer etc. It aims to provide more modular layers for Ruby on Rails
85
+ applications.
71
86
  email: ryohashimoto@gmail.com
72
87
  executables: []
73
88
  extensions: []
74
89
  extra_rdoc_files: []
75
90
  files:
91
+ - LICENSE
76
92
  - README.md
93
+ - RELEASE_DATE
94
+ - VERSION
95
+ - lib/generators/action_facade/install_generator.rb
96
+ - lib/generators/action_facade/templates/application_facade.rb
97
+ - lib/generators/action_interactor/install_generator.rb
98
+ - lib/generators/action_interactor/templates/application_interactor.rb
99
+ - lib/generators/active_representer/install_generator.rb
100
+ - lib/generators/active_representer/templates/application_representer.rb
101
+ - lib/generators/facade_generator.rb
102
+ - lib/generators/interactor_generator.rb
103
+ - lib/generators/representer_generator.rb
104
+ - lib/generators/templates/facade.tt
105
+ - lib/generators/templates/interactor.tt
106
+ - lib/generators/templates/representer.tt
107
+ - lib/lightrails.rb
77
108
  homepage: https://github.com/ryohashimoto/lightrails
78
109
  licenses:
79
110
  - MIT
@@ -97,5 +128,6 @@ rubyforge_project:
97
128
  rubygems_version: 2.7.6
98
129
  signing_key:
99
130
  specification_version: 4
100
- summary: Utility library for Ruby on Rails
131
+ summary: Utility library including Action Facade, Action Interactor, Active Representer
132
+ etc. (for Ruby on Rails)
101
133
  test_files: []