alki-rails 0.3.0 → 0.4.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/README.adoc +76 -20
- data/lib/alki/rails/version.rb +1 -1
- data/lib/rails/generators/alki_generator.rb +18 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 45051ebb8bd2da6d7be68dbd16d3a3b4335376e4
|
4
|
+
data.tar.gz: a580d8affd5429b300e30ba5b5530d82222f830a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 712474223f299549e697bdb74c84b21007944eb42cf42f2d126df4810bc7af38b8d769aba0b5edf44e181cb5b82aa7ff3ae979b5cd346ce4842322e34a629bae
|
7
|
+
data.tar.gz: fdf6f58c8757dee87d669fe41fe3ffb25a0ab6200af0721707c422fc0d3b60d88832a184cd5bac01121f84bad81e71945316bfd5ae879cff6097a696c2d370c4
|
data/README.adoc
CHANGED
@@ -4,7 +4,26 @@ Rails integration for Alki! Allows easily using Alki in your Rails project. Alki
|
|
4
4
|
|
5
5
|
== Why use Alki with Rails?
|
6
6
|
|
7
|
+
While Rails is a fantastic web framework, it doesn't offer a lot of tools to manage your
|
8
|
+
core business logic. Common idioms like "Fat Model" or "Fat Controller" work ok for a while,
|
9
|
+
but most large Rails projects get to a point where their business logic grows beyond
|
10
|
+
Rails' basic MVC paradigm.
|
7
11
|
|
12
|
+
Using Alki to manage your business logic allows your Rails code to focus on what it does best:
|
13
|
+
serve web pages. With Alki::Rails, Alki integrates seamlessly with Rails, while also keeping
|
14
|
+
your core code encapsulated.
|
15
|
+
|
16
|
+
=== What about Rails Services?
|
17
|
+
|
18
|
+
Recent versions of Rails have added an `app/services` directory as a place to put
|
19
|
+
dedicated service objects containing your business logic.
|
20
|
+
|
21
|
+
The key difference between these Rails services and Alki services is that Rails services are
|
22
|
+
classes or modules, referenced directly by consumers when needed, while Alki services can be
|
23
|
+
any time of object, but are typically instances of a service class.
|
24
|
+
|
25
|
+
By using instances, Alki allows services to be configured and dependency injected before
|
26
|
+
being used.
|
8
27
|
|
9
28
|
== Installation
|
10
29
|
|
@@ -22,25 +41,72 @@ And then execute:
|
|
22
41
|
$ bundle
|
23
42
|
----
|
24
43
|
|
25
|
-
|
44
|
+
Finally, run the generator to create an empty `config/assembly.rb` and to make your
|
45
|
+
assembly elements accessible in your controllers and in the console.
|
46
|
+
|
47
|
+
[source]
|
48
|
+
----
|
49
|
+
$ bin/rails generate alki
|
50
|
+
----
|
51
|
+
|
52
|
+
== Usage
|
53
|
+
|
54
|
+
Elements like services and application settings are defined in your Assembly definition
|
55
|
+
(`config/assembly.rb`). These elements are accessible by name directly within controllers
|
56
|
+
and the rails console.
|
57
|
+
|
58
|
+
See https://github.com/alki-project/alki[here] for more documentation on how to use Alki.
|
26
59
|
|
27
60
|
.config/assembly.rb
|
28
61
|
```ruby
|
29
62
|
Alki do
|
63
|
+
group :orders do
|
64
|
+
service :manager do
|
65
|
+
require 'order_manager'
|
66
|
+
OrderManager.new model, payment_processor
|
67
|
+
end
|
68
|
+
|
69
|
+
service :model do
|
70
|
+
Order
|
71
|
+
end
|
72
|
+
|
73
|
+
service :payment_processor do
|
74
|
+
require 'stripe_processor'
|
75
|
+
StripeProcessor.new
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
```
|
30
80
|
|
81
|
+
.app/controllers/orders_controller.rb
|
82
|
+
```ruby
|
83
|
+
class OrdersController < ApplicationController
|
84
|
+
def post
|
85
|
+
@order = orders.manager.place_order params[:order]
|
86
|
+
end
|
31
87
|
end
|
32
88
|
```
|
33
89
|
|
34
|
-
|
90
|
+
.lib/order_manager.rb
|
91
|
+
```ruby
|
92
|
+
class OrderManager
|
93
|
+
def initialize(model,payment_processor)
|
94
|
+
@model = model
|
95
|
+
@payment_processor = payment_processor
|
96
|
+
end
|
35
97
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
----
|
98
|
+
...
|
99
|
+
end
|
100
|
+
```
|
40
101
|
|
41
|
-
|
102
|
+
.lib/stripe_processor.rb
|
103
|
+
```ruby
|
104
|
+
class StripeProcessor
|
105
|
+
...
|
106
|
+
end
|
107
|
+
```
|
42
108
|
|
43
|
-
|
109
|
+
Elements can also be accessed anywhere in your Rails application, via `Alki::Rails`:
|
44
110
|
|
45
111
|
.config/assembly.rb
|
46
112
|
```ruby
|
@@ -51,26 +117,16 @@ Alki do
|
|
51
117
|
end
|
52
118
|
```
|
53
119
|
|
54
|
-
.app/controllers/home_controller.rb
|
55
|
-
```ruby
|
56
|
-
class HomeController < ApplicationController
|
57
|
-
def show
|
58
|
-
@msg = settings.msg
|
59
|
-
end
|
60
|
-
end
|
61
|
-
```
|
62
|
-
|
63
|
-
Elements can also be accessed in the Rails console, or anywhere else in your Rails application, via Alki::Rails:
|
64
|
-
|
65
120
|
.Rails Console
|
66
121
|
```
|
122
|
+
2.3.2 :001 > settings.msg
|
123
|
+
=> 'Hello World'
|
67
124
|
2.3.2 :001 > Alki::Rails.settings.msg
|
68
125
|
=> 'Hello World'
|
69
126
|
```
|
70
127
|
|
71
128
|
Alki will automatically add your projects `lib` directory to the ruby load path, so you can require files from there directly. It also will handle auto-reloading files in lib.
|
72
129
|
|
73
|
-
See https://github.com/alki-project/alki[here] for more documentation on how to use Alki.
|
74
130
|
|
75
131
|
== Contributing
|
76
132
|
|
data/lib/alki/rails/version.rb
CHANGED
@@ -0,0 +1,18 @@
|
|
1
|
+
class AlkiGenerator < Rails::Generators::Base
|
2
|
+
def create_initializer
|
3
|
+
create_file "config/assembly.rb", <<END
|
4
|
+
Alki do
|
5
|
+
# elements go here ...
|
6
|
+
end
|
7
|
+
END
|
8
|
+
create_file "config/initializers/alki.rb", <<END
|
9
|
+
module Rails::ConsoleMethods
|
10
|
+
include Alki::Rails
|
11
|
+
end
|
12
|
+
|
13
|
+
class ActionController::Base
|
14
|
+
include Alki::Rails
|
15
|
+
end
|
16
|
+
END
|
17
|
+
end
|
18
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: alki-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt Edlefsen
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-03-
|
11
|
+
date: 2017-03-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -83,6 +83,7 @@ files:
|
|
83
83
|
- lib/alki-rails.rb
|
84
84
|
- lib/alki/rails.rb
|
85
85
|
- lib/alki/rails/version.rb
|
86
|
+
- lib/rails/generators/alki_generator.rb
|
86
87
|
homepage: https://github.com/alki-project/alki-rails
|
87
88
|
licenses:
|
88
89
|
- MIT
|