mutations_generator 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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 97cc68333b5701d9effc3801c5b63c27099b8926291bcb2972ae9c5c53c8663b
4
+ data.tar.gz: 2cb85f674e04c8f92d1e65ff6877946ffb51d1c7594836a9d08e81c4731da5ff
5
+ SHA512:
6
+ metadata.gz: 37afed42f7997559d9569eecce9e9005e339bec0e867bf00c5ee5e234e8a5a43703a0959958dfa855be408b0d18bee586ffb8721893ff2c5c4af3b2a52893a27
7
+ data.tar.gz: 569928075db80fa724a163752f2deb3b9b160d8ced7aac9c5bbaee090750218d3f4e443f80c8c3f905e8f32e46d931d322838b9024c23de88e71430308c30edb
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ *.gem
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in mutation_generator.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
@@ -0,0 +1,145 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ mutations_generator (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ actioncable (6.0.3.2)
10
+ actionpack (= 6.0.3.2)
11
+ nio4r (~> 2.0)
12
+ websocket-driver (>= 0.6.1)
13
+ actionmailbox (6.0.3.2)
14
+ actionpack (= 6.0.3.2)
15
+ activejob (= 6.0.3.2)
16
+ activerecord (= 6.0.3.2)
17
+ activestorage (= 6.0.3.2)
18
+ activesupport (= 6.0.3.2)
19
+ mail (>= 2.7.1)
20
+ actionmailer (6.0.3.2)
21
+ actionpack (= 6.0.3.2)
22
+ actionview (= 6.0.3.2)
23
+ activejob (= 6.0.3.2)
24
+ mail (~> 2.5, >= 2.5.4)
25
+ rails-dom-testing (~> 2.0)
26
+ actionpack (6.0.3.2)
27
+ actionview (= 6.0.3.2)
28
+ activesupport (= 6.0.3.2)
29
+ rack (~> 2.0, >= 2.0.8)
30
+ rack-test (>= 0.6.3)
31
+ rails-dom-testing (~> 2.0)
32
+ rails-html-sanitizer (~> 1.0, >= 1.2.0)
33
+ actiontext (6.0.3.2)
34
+ actionpack (= 6.0.3.2)
35
+ activerecord (= 6.0.3.2)
36
+ activestorage (= 6.0.3.2)
37
+ activesupport (= 6.0.3.2)
38
+ nokogiri (>= 1.8.5)
39
+ actionview (6.0.3.2)
40
+ activesupport (= 6.0.3.2)
41
+ builder (~> 3.1)
42
+ erubi (~> 1.4)
43
+ rails-dom-testing (~> 2.0)
44
+ rails-html-sanitizer (~> 1.1, >= 1.2.0)
45
+ activejob (6.0.3.2)
46
+ activesupport (= 6.0.3.2)
47
+ globalid (>= 0.3.6)
48
+ activemodel (6.0.3.2)
49
+ activesupport (= 6.0.3.2)
50
+ activerecord (6.0.3.2)
51
+ activemodel (= 6.0.3.2)
52
+ activesupport (= 6.0.3.2)
53
+ activestorage (6.0.3.2)
54
+ actionpack (= 6.0.3.2)
55
+ activejob (= 6.0.3.2)
56
+ activerecord (= 6.0.3.2)
57
+ marcel (~> 0.3.1)
58
+ activesupport (6.0.3.2)
59
+ concurrent-ruby (~> 1.0, >= 1.0.2)
60
+ i18n (>= 0.7, < 2)
61
+ minitest (~> 5.1)
62
+ tzinfo (~> 1.1)
63
+ zeitwerk (~> 2.2, >= 2.2.2)
64
+ builder (3.2.4)
65
+ concurrent-ruby (1.1.7)
66
+ crass (1.0.6)
67
+ erubi (1.9.0)
68
+ globalid (0.4.2)
69
+ activesupport (>= 4.2.0)
70
+ i18n (1.8.5)
71
+ concurrent-ruby (~> 1.0)
72
+ loofah (2.6.0)
73
+ crass (~> 1.0.2)
74
+ nokogiri (>= 1.5.9)
75
+ mail (2.7.1)
76
+ mini_mime (>= 0.1.1)
77
+ marcel (0.3.3)
78
+ mimemagic (~> 0.3.2)
79
+ method_source (1.0.0)
80
+ mimemagic (0.3.5)
81
+ mini_mime (1.0.2)
82
+ mini_portile2 (2.4.0)
83
+ minitest (5.14.1)
84
+ mutations (0.9.1)
85
+ activesupport
86
+ nio4r (2.5.2)
87
+ nokogiri (1.10.10)
88
+ mini_portile2 (~> 2.4.0)
89
+ rack (2.2.3)
90
+ rack-test (1.1.0)
91
+ rack (>= 1.0, < 3)
92
+ rails (6.0.3.2)
93
+ actioncable (= 6.0.3.2)
94
+ actionmailbox (= 6.0.3.2)
95
+ actionmailer (= 6.0.3.2)
96
+ actionpack (= 6.0.3.2)
97
+ actiontext (= 6.0.3.2)
98
+ actionview (= 6.0.3.2)
99
+ activejob (= 6.0.3.2)
100
+ activemodel (= 6.0.3.2)
101
+ activerecord (= 6.0.3.2)
102
+ activestorage (= 6.0.3.2)
103
+ activesupport (= 6.0.3.2)
104
+ bundler (>= 1.3.0)
105
+ railties (= 6.0.3.2)
106
+ sprockets-rails (>= 2.0.0)
107
+ rails-dom-testing (2.0.3)
108
+ activesupport (>= 4.2.0)
109
+ nokogiri (>= 1.6)
110
+ rails-html-sanitizer (1.3.0)
111
+ loofah (~> 2.3)
112
+ railties (6.0.3.2)
113
+ actionpack (= 6.0.3.2)
114
+ activesupport (= 6.0.3.2)
115
+ method_source
116
+ rake (>= 0.8.7)
117
+ thor (>= 0.20.3, < 2.0)
118
+ rake (12.3.3)
119
+ sprockets (4.0.2)
120
+ concurrent-ruby (~> 1.0)
121
+ rack (> 1, < 3)
122
+ sprockets-rails (3.2.1)
123
+ actionpack (>= 4.0)
124
+ activesupport (>= 4.0)
125
+ sprockets (>= 3.0.0)
126
+ thor (1.0.1)
127
+ thread_safe (0.3.6)
128
+ tzinfo (1.2.7)
129
+ thread_safe (~> 0.1)
130
+ websocket-driver (0.7.3)
131
+ websocket-extensions (>= 0.1.0)
132
+ websocket-extensions (0.1.5)
133
+ zeitwerk (2.4.0)
134
+
135
+ PLATFORMS
136
+ ruby
137
+
138
+ DEPENDENCIES
139
+ mutations (~> 0.9.1)
140
+ mutations_generator!
141
+ rails (~> 6.0.3.1)
142
+ rake (~> 12.0)
143
+
144
+ BUNDLED WITH
145
+ 2.1.2
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 robertsimoes
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
13
+ all 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
21
+ THE SOFTWARE.
@@ -0,0 +1,34 @@
1
+ # MutationsGenerator
2
+
3
+ Rails generator extension for the [mutations](https://github.com/cypriss/mutations) framework.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'mutations_generator'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle install
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install mutations_generator
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Development
26
+
27
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
28
+
29
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
30
+
31
+
32
+ ## License
33
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
34
+
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
@@ -0,0 +1 @@
1
+ rm -f mutations_generator-0.1.0.gem && gem build mutations_generator.gemspec && gem install mutations_generator-0.1.0.gem
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "mutations_generator"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,10 @@
1
+ Description:
2
+ Adds a new Mutation to your application. Provide the mutation name as CamelCased or snake_cased.
3
+ Pass a list of inputs as arguments with their types and if they are required or optional.
4
+ This generates a mutation class in app/mutations.
5
+
6
+ Example:
7
+ rails generate mutation PumpTheJam technotronic:model:required space_jam:string:optional
8
+
9
+ This will create:
10
+ app/mutations/pump_the_jam.rb
@@ -0,0 +1,73 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails/generators/base'
4
+
5
+ class MutationGenerator < Rails::Generators::NamedBase
6
+ source_root File.expand_path('templates', __dir__)
7
+
8
+ argument :inputs, type: :array, default: [], banner: 'attribute[:filter][:required] attribute[:filter][:optional]'
9
+
10
+ def create_mutation_file
11
+ mutation_dir_path = 'app/mutations'
12
+ generator_path = mutation_dir_path + "/#{file_name}.rb"
13
+
14
+ Dir.mkdir(mutation_dir_path) unless File.exist?(mutation_dir_path)
15
+
16
+ set_local_assigns!
17
+
18
+ template 'mutation.erb', generator_path
19
+ end
20
+
21
+ def set_local_assigns!
22
+ ins = inputs.clone
23
+ attributes = ins.map { |i| GeneratedAttribute.parse(i) }
24
+ @required = attributes.select { |a| a.input_type == 'required' }
25
+ @optional = attributes.select { |a| a.input_type == 'optional' }
26
+ @klass_name = file_name.camelize
27
+ end
28
+
29
+ class GeneratedAttribute
30
+ FILTER_OPTIONS = %w[string integer model hash array boolean date duck input symbol time].freeze
31
+ INPUT_OPTIONS = %w[required optional].freeze
32
+
33
+ attr_accessor :name, :filter, :input_type
34
+
35
+ class << self
36
+ def parse(definition)
37
+ name, filter, input_type = definition.split(':')
38
+ raise 'name required' if name.nil?
39
+ raise 'filter type required' if filter.nil?
40
+
41
+ input_type ||= 'required'
42
+
43
+ filter = validate_filter!(filter)
44
+ input_type = validate_input_type!(input_type)
45
+ name = name.to_sym
46
+
47
+ new(name, filter, input_type)
48
+ end
49
+
50
+ def validate_input_type!(input_type)
51
+ unless INPUT_OPTIONS.include?(input_type)
52
+ raise "invalid input type must be one of #{INPUT_OPTIONS}"
53
+ end
54
+
55
+ input_type
56
+ end
57
+
58
+ def validate_filter!(filter)
59
+ unless FILTER_OPTIONS.include?(filter)
60
+ raise "invalid filter type must be one of #{FILTER_OPTIONS}"
61
+ end
62
+
63
+ filter
64
+ end
65
+ end
66
+
67
+ def initialize(name, filter, input_type)
68
+ @name = name
69
+ @filter = filter || 'string'
70
+ @input_type = input_type || 'required'
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,26 @@
1
+ class <%= @klass_name %> < Mutations::Command
2
+ <% if !@required.empty? %>
3
+ required do
4
+ <% @required.each do |i|%>
5
+ <%= i.filter %> :<%= i.name %>
6
+ <% end %>
7
+ end
8
+ <% end %>
9
+
10
+ <% if !@optional.empty? %>
11
+ optional do
12
+ <% @optional.each do |i|%>
13
+ <%= i.filter %> :<%= i.name %>
14
+ <% end %>
15
+ end
16
+ <% end %>
17
+
18
+ def validate
19
+ # TODO your validation logic goes here
20
+ # add_error(:input, :symbol_error, "There has been a major malfunction")
21
+ end
22
+
23
+ def execute
24
+ # TODO your business logic goes here
25
+ end
26
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'mutations_generator/version'
4
+
5
+ module MutationsGenerator
6
+ class Error < StandardError; end
7
+ # Your code goes here...
8
+ end
@@ -0,0 +1,3 @@
1
+ module MutationsGenerator
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/mutations_generator/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'mutations_generator'
7
+ spec.version = MutationsGenerator::VERSION
8
+ spec.authors = ['robertsimoes']
9
+ spec.email = ['robertsimoes@users.noreply.github.com']
10
+
11
+ spec.summary = 'Extension for Ruby on Rails to add Mutation generators'
12
+ spec.description = 'Mutations are an elegant implementation of the Command and ServiceObject pattern in Ruby on Rails projects. This gem extends Rails generators to include a mutation generator.'
13
+ spec.homepage = 'https://github.com/robertsimoes'
14
+ spec.license = 'MIT'
15
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
16
+
17
+ spec.metadata['homepage_uri'] = spec.homepage
18
+ spec.metadata['source_code_uri'] = 'https://github.com/robertsimoes'
19
+ spec.metadata['changelog_uri'] = spec.metadata['source_code_uri'] + '/releases'
20
+
21
+ # Specify which files should be added to the gem when it is released.
22
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
24
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
+ end
26
+ spec.bindir = 'exe'
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ['lib']
29
+ spec.add_development_dependency 'mutations', '~> 0.9.1'
30
+ spec.add_development_dependency 'rails', '~>6.0.3.1'
31
+ end
metadata ADDED
@@ -0,0 +1,91 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mutations_generator
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - robertsimoes
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-08-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: mutations
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.9.1
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.9.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: rails
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 6.0.3.1
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 6.0.3.1
41
+ description: Mutations are an elegant implementation of the Command and ServiceObject
42
+ pattern in Ruby on Rails projects. This gem extends Rails generators to include
43
+ a mutation generator.
44
+ email:
45
+ - robertsimoes@users.noreply.github.com
46
+ executables: []
47
+ extensions: []
48
+ extra_rdoc_files: []
49
+ files:
50
+ - ".gitignore"
51
+ - Gemfile
52
+ - Gemfile.lock
53
+ - LICENSE.txt
54
+ - README.md
55
+ - Rakefile
56
+ - bin/build_gem_local
57
+ - bin/console
58
+ - bin/setup
59
+ - lib/generators/mutation/USAGE
60
+ - lib/generators/mutation/mutation_generator.rb
61
+ - lib/generators/mutation/templates/mutation.erb
62
+ - lib/mutations_generator.rb
63
+ - lib/mutations_generator/version.rb
64
+ - mutations_generator.gemspec
65
+ homepage: https://github.com/robertsimoes
66
+ licenses:
67
+ - MIT
68
+ metadata:
69
+ homepage_uri: https://github.com/robertsimoes
70
+ source_code_uri: https://github.com/robertsimoes
71
+ changelog_uri: https://github.com/robertsimoes/releases
72
+ post_install_message:
73
+ rdoc_options: []
74
+ require_paths:
75
+ - lib
76
+ required_ruby_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: 2.3.0
81
+ required_rubygems_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ requirements: []
87
+ rubygems_version: 3.1.2
88
+ signing_key:
89
+ specification_version: 4
90
+ summary: Extension for Ruby on Rails to add Mutation generators
91
+ test_files: []