easy_gen 1.5.1 → 1.6.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: afdc2c7d450b407a19e0b5a82f98940bd963e5c2834d60e21779dfd9d13d957b
4
- data.tar.gz: 4fc94179b298f2d5fcf1d86616ff0a97f305f4a0f44251d7a5624087fa5e7969
3
+ metadata.gz: 9b7d64c79858b893ced2e81bed3e518b5b7ed1ad9b75bccaafff168da7c3fdbe
4
+ data.tar.gz: d5ffd68cd6b866b042ec829060a1020343491d45afbfee9f62bd8a91ac32c9f6
5
5
  SHA512:
6
- metadata.gz: 30a98e94af6ca028739c7e19ae5eb9e2c830faf35ad2ba55627317cf7ea52dd4e4f7d772ded27626db44771e06c5dc55e9000e0d8a8d98a5e474418a9b6f1084
7
- data.tar.gz: eb49eaf5177912c6f5820797523b437435c2c8cf9f36c2d1577199956da1b8e2bf95847f15bf76037d42e47c3d375f536c595b255ec13d3c4884b00b2d6875b1
6
+ metadata.gz: 1567545a32fe9c69c143c209bd866c392b76e9c67275f499907a7046302c94e7495b0e7cc58fd30921636847772f7b29d0c448faf1fe8a87447480513d2841cf
7
+ data.tar.gz: 2dc1c54f78caf7a901b22dbdb4d298ff46bfcee2d2f5c9fb39b26bacf49005e7ca89fa2b839e00124827be2927e416c004b29e18bd331e5263df5b989ecebb6c
data/README.md CHANGED
@@ -134,6 +134,24 @@ The command above:
134
134
  - Installs new test class in '/test/strategies/fishing' with the name 'LineStrategy' in the file '/test/strategies/line_strategy_test.rb'.
135
135
  - Installs new test class in '/test/strategies/fishing' with the name 'NetStrategy' in the file '/test/strategies/net_strategy_test.rb'.
136
136
 
137
+ ### Serializer Classes
138
+ If you want to do something other than standard JSON serialization...
139
+
140
+ ```sh
141
+ bundle exec rails g serializer basic
142
+ ```
143
+
144
+ The command above:
145
+
146
+ - Creates '/app/serializers' directory if it doesnt exist.
147
+ - Installs new application serializer class in '/app/serializers' with the name 'ApplicationSerializer' in file '/app/decorators/application_serializer.rb.'.
148
+ - Installs new serializer class in '/app/serializer' with the class name 'BasicSerializer' in the file /app/decorators/basic_seralizer.rb. This will inherit from /app/decorators/application_serializer.rb.'
149
+ - Creates '/test/serializers' directory if it doesnt exist.
150
+ - Installs new test class in '/test/serializers' with the name 'BasicSerializerTest' in the file '/test/decorators/basic_serializer_test.rb'.
151
+
152
+
153
+ Module option is also supported.
154
+
137
155
 
138
156
  ## Summary
139
157
  ** Saves a bit of typing
@@ -42,8 +42,6 @@ class NullGenerator < Rails::Generators::NamedBase
42
42
  end
43
43
 
44
44
  def clazz
45
- eg_debug "**** Model: #{model_name} - #{model_name.class} - #{model_name.method(:constantize).source_location} ****"
46
-
47
45
  model_name.constantize
48
46
  end
49
47
 
@@ -0,0 +1,14 @@
1
+ Description:
2
+ Lays out a new serializers object under /app/serializers, with a test file under /test/serializers.
3
+ The null value class will inherit from /app/serializers/application_serializer.rb class which will be created.
4
+ if you use the generator to delete null classes, these will be removed together with directories once
5
+ the count of non abstract classes == 0.
6
+
7
+ Example:
8
+ `rails generate serializer MySerializer`
9
+
10
+ This will create:
11
+ app/serializers/application_serializer.rb
12
+ app/serializers/my_serializer.rb
13
+ test/serializers/my_serializer_test.rb
14
+
@@ -0,0 +1,25 @@
1
+ require 'rails/all'
2
+ require 'rails/generators'
3
+ require 'fileutils'
4
+
5
+ template_dir = File.expand_path('templates', __dir__)
6
+
7
+ class SerializerGenerator < Rails::Generators::NamedBase
8
+ include EasyGenGenerator
9
+ # bundle exec rails g null MyModel
10
+ # bundle exec rails d null MyModel
11
+
12
+ LOCATION = "serializers"
13
+ TYPE = "serializer"
14
+
15
+ source_root File.expand_path("templates", __dir__)
16
+
17
+ class_option :module, type: :string
18
+
19
+ def main
20
+ copy_templates
21
+ end
22
+
23
+ private
24
+
25
+ end
@@ -0,0 +1,22 @@
1
+ # Or consider this..
2
+ # $ bundle add jserializer
3
+ #
4
+ #class ApplicationSerializer < Jserializer::Base
5
+ # attributes :data
6
+ #
7
+ # def some_value
8
+ # object.some_value.somewhere
9
+ # end
10
+ #end
11
+
12
+ # dumb coder..
13
+ class ApplicationSerializer
14
+
15
+ def load(data)
16
+ @data = data || {}
17
+ end
18
+
19
+ def dump
20
+ @data || {}
21
+ end
22
+ end
@@ -0,0 +1,3 @@
1
+ class <%= module_prefix %><%= class_name %>Serializer < ApplicationSerializer
2
+
3
+ end
@@ -0,0 +1,32 @@
1
+ require "test_helper"
2
+
3
+ class <%= module_prefix %><%= class_name %>SerlializerTest < ActiveSupport::TestCase
4
+ setup do
5
+ @serializer = <%= module_prefix %><%= class_name %>Serializer.new
6
+ @data = "The data"
7
+ end
8
+
9
+ test 'it is empty on initialization' do
10
+ assert <%= module_prefix %><%= class_name %>Serializer.new.dump == {}
11
+ end
12
+
13
+ test 'it loads data' do
14
+ assert @serializer.load(@data)
15
+ end
16
+
17
+ test 'it dumps data' do
18
+ assert_not_nil @serializer.dump
19
+ end
20
+
21
+ test 'it maintains original data' do
22
+ @serializer.load(@data)
23
+ assert_equal @serializer.dump, @data
24
+ end
25
+
26
+ test 'it replaces data' do
27
+ assert @serializer.load("Rubbish")
28
+ assert_equal @serializer.dump, "Rubbish"
29
+ end
30
+
31
+ end
32
+
@@ -1,3 +1,3 @@
1
1
  module EasyGen
2
- VERSION = "1.5.1"
2
+ VERSION = "1.6.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: easy_gen
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.1
4
+ version: 1.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Simon Stearn
@@ -32,6 +32,11 @@ files:
32
32
  - lib/easy_gen/null/templates/null.rb.tt
33
33
  - lib/easy_gen/null/templates/null_test.rb.tt
34
34
  - lib/easy_gen/railtie.rb
35
+ - lib/easy_gen/serializer/USAGE
36
+ - lib/easy_gen/serializer/serializer_generator.rb
37
+ - lib/easy_gen/serializer/templates/application_serializer.rb.tt
38
+ - lib/easy_gen/serializer/templates/serializer.rb.tt
39
+ - lib/easy_gen/serializer/templates/serializer_test.rb.tt
35
40
  - lib/easy_gen/service/USAGE
36
41
  - lib/easy_gen/service/service_generator.rb
37
42
  - lib/easy_gen/service/templates/application_service.rb.tt