power-types 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +98 -0
  3. data/lib/power_types/version.rb +1 -1
  4. metadata +3 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9d8d84c3744f92654b42fb2ccd339cf2c1e89c10
4
- data.tar.gz: b1583c97cb542a6284b0389822e421516bfbd3b0
3
+ metadata.gz: f159dd5e4a3a526a40fec330c362de8a529eb047
4
+ data.tar.gz: 970394597addd67d70142b5dd64a98a96a5098ce
5
5
  SHA512:
6
- metadata.gz: 23e19ac6431e3231a5591b1cead007eb69c1a2e13b7e086192bae32a893b286b522bb9fa24ab16749fa2a8da66cf9ba294a95b04f7587d265df5a80afef9039f
7
- data.tar.gz: 6a0a8aafd3056d2b2fe01049c3c7519d174d341d00a877487e4511f77cb5b47dd68386bec7c424028a2da56ca21a4d6bb4772ed9d81208cf044690a6b1878aaa
6
+ metadata.gz: 34896843282a2ac5eaf399c199825f1f221f42525521d7ce95a49ee7bc698d666c147de92128391e9c09b28076e6e7a051b3eb36b2820d050b3558ed5ef21f65
7
+ data.tar.gz: 00959cdba7efdabbedf520cdb031122c8a17e9814ee9ce18f327d92aced0b1956b0842284b378eb83427db7efc1dd1727b36617ac4697577cae661bb03db0508
data/README.md ADDED
@@ -0,0 +1,98 @@
1
+ # Power-Types
2
+
3
+ Rails pattern enforcing types used by the Platanus team
4
+
5
+ ## Introduction
6
+
7
+ In Rails projects, Platanus encourages to use classes beyond models and controllers to hold the app's logic.
8
+ These powerful types proposed are Services, Commands, Utils and Values.
9
+
10
+ For a deeper understanding about the usage of these patterns, feel welcome to read the [related post in Platanus Blog](https://cb.platan.us/services-commands-y-otros-poderosos-patrones-en-rails) (in spanish).
11
+
12
+ The goal aimed with this gem is to go further, and not just apply this patterns over POROs (plain simple ruby classes). The gem provides an special structure and syntax to create and run Services and Commands with ease.
13
+
14
+ It also creates the directory for each type, and provides generators.
15
+
16
+ ## Usage
17
+
18
+ ### Generators
19
+
20
+ For generating services we use:
21
+
22
+ $ rails generate service MagicMakingService foo bar
23
+
24
+ This will create the MagicMakingService class, inheriting from a base service class:
25
+
26
+ class MagicMakingService < PowerTypes::Service.new(:foo, bar: nil)
27
+
28
+ Default values for arguments are optional, and can't be defined in the generator, but manually after. In this case a `nil` value was given for `bar`.
29
+ This is a way to make the argument optional. If no default value is assigned, the argument will be required, and an error raised if missing.
30
+
31
+ This generator will create its corresponding rspec file.
32
+
33
+
34
+
35
+ For generating commands:
36
+
37
+ $ rails generate command MakeMagic foo bar
38
+
39
+ Which will generate the corresponding class, with the `perform` method. This method must be implemented, and its called when the command is executed.
40
+
41
+ class MakeMagic < PowerTypes::Command.new(:foo, bar: nil)
42
+
43
+ And in a similar way to services, the command's spec file is also created by this generator
44
+
45
+ ### Instantiate and Run
46
+
47
+ We can create service objects like this
48
+
49
+ magic_service = MagicMakingService.new(foo: my_foo, bar: "a bar")
50
+
51
+ And use any method the service provides
52
+
53
+ magic_service.gandalfize(sauron)
54
+ magic_service.harry_potterize(voldemort)
55
+
56
+ In the case of commands, we are not suposed to store or reuse the object. You just want to run it and keep the result
57
+
58
+ result = MakeMagic.for(foo: a_foo, bar: "i'm bar")
59
+
60
+ ### Values and Utils
61
+
62
+ This two types do not have generators.
63
+
64
+ Values are just simple Ruby classes, but watch out to keep them in the Values directory!
65
+
66
+ Utils should be defined as a module. There you define the independent but related functions. Use the extend self pattern to call them directly after the module name.
67
+ ```ruby
68
+ module MagicTricks
69
+ extend self
70
+
71
+ def dissappear(object)
72
+ #blah blah
73
+ end
74
+
75
+ def shrink(children)
76
+ #bleh bleeh
77
+ end
78
+
79
+ def shuffle(cards)
80
+ #blaah
81
+ end
82
+ ```
83
+ Example of calling a Util function:
84
+
85
+ MagicTricks.dissapear(rabbit)
86
+
87
+
88
+ ## Credits
89
+
90
+ Thank you [contributors](https://github.com/platanus/power-types/graphs/contributors)!
91
+
92
+ <img src="http://platan.us/gravatar_with_text.png" alt="Platanus" width="250"/>
93
+
94
+ Power-Types is maintained by [platanus](http://platan.us).
95
+
96
+ ## License
97
+
98
+ Power-Types is © 2016 Platanus, S.p.A. It is free software and may be redistributed under the terms specified in the LICENSE file.
@@ -1,3 +1,3 @@
1
1
  module PowerTypes
2
- VERSION = '0.0.1'
2
+ VERSION = '0.1.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: power-types
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ignacio Baixas
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2016-07-14 00:00:00.000000000 Z
12
+ date: 2016-08-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -186,6 +186,7 @@ files:
186
186
  - Gemfile
187
187
  - Guardfile
188
188
  - LICENSE.txt
189
+ - README.md
189
190
  - Rakefile
190
191
  - lib/generators/power_types/init_generator.rb
191
192
  - lib/generators/rails/command_generator.rb