g2_command 0.1.0 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 77dad168ef55ca1a4265b1dabf2834eed591ec975ea1dec3bc8d2d33bbc03a8c
4
- data.tar.gz: c67ef31b7ca990bffa8980def958c910357be7b0e4c8642bb1654123c429dbe6
3
+ metadata.gz: f13db20c39897ba62b772df83fa08669c50ed453e4986de8e212a150d8beed8d
4
+ data.tar.gz: 1201c0befff3595658f299b527cea3116c2a7d6717197c0e3c091b2165999217
5
5
  SHA512:
6
- metadata.gz: 9308bedbfa3b49ee7fb73099735dfc9b66c5dfbdf4e3faadd6a6aa0ef256f7adc986718dea96974aefc15cdf6a0ce6b0a6632dfd304637d0bcb451e55a4176bc
7
- data.tar.gz: 6ba4102ec3a28e0ce6ca769b4be804ee4cf77137dc51770c14fc95befebb017b804d68987de47c1ffc4ccc3e7a815d57ea78702172373329617e11edb2071f98
6
+ metadata.gz: 30a07c7dbbc9918c729e49bd539202209f162367f57a2e4bdd3f65a899bce59ad0f726e342b2f4caa3aeb30c71f8dc94d6846fab0f8452b976a1262ce530d97c
7
+ data.tar.gz: a7a1011d0dd407c4873cbc533f151abd87bf35fa25d1e02915f9f0cc400aa20c626d3dd29a850747f5a4959714e2d47af3d66ee485f3c4e54cf625e2af6f9b46
data/Gemfile CHANGED
@@ -4,6 +4,8 @@ source 'https://rubygems.org'
4
4
 
5
5
  gemspec
6
6
 
7
+ gem 'pry'
8
+ gem 'rails'
7
9
  gem 'rake', '~> 12.0'
8
10
  gem 'rspec', '~> 3.0'
9
11
  gem 'rubocop'
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- g2_command (0.1.0)
4
+ g2_command (0.2.0)
5
5
  activemodel (>= 6.0, < 7)
6
6
  activesupport (>= 6.0, < 7)
7
7
  dry-initializer (~> 3.0)
@@ -10,8 +10,55 @@ PATH
10
10
  GEM
11
11
  remote: https://rubygems.org/
12
12
  specs:
13
+ actioncable (6.0.2.2)
14
+ actionpack (= 6.0.2.2)
15
+ nio4r (~> 2.0)
16
+ websocket-driver (>= 0.6.1)
17
+ actionmailbox (6.0.2.2)
18
+ actionpack (= 6.0.2.2)
19
+ activejob (= 6.0.2.2)
20
+ activerecord (= 6.0.2.2)
21
+ activestorage (= 6.0.2.2)
22
+ activesupport (= 6.0.2.2)
23
+ mail (>= 2.7.1)
24
+ actionmailer (6.0.2.2)
25
+ actionpack (= 6.0.2.2)
26
+ actionview (= 6.0.2.2)
27
+ activejob (= 6.0.2.2)
28
+ mail (~> 2.5, >= 2.5.4)
29
+ rails-dom-testing (~> 2.0)
30
+ actionpack (6.0.2.2)
31
+ actionview (= 6.0.2.2)
32
+ activesupport (= 6.0.2.2)
33
+ rack (~> 2.0, >= 2.0.8)
34
+ rack-test (>= 0.6.3)
35
+ rails-dom-testing (~> 2.0)
36
+ rails-html-sanitizer (~> 1.0, >= 1.2.0)
37
+ actiontext (6.0.2.2)
38
+ actionpack (= 6.0.2.2)
39
+ activerecord (= 6.0.2.2)
40
+ activestorage (= 6.0.2.2)
41
+ activesupport (= 6.0.2.2)
42
+ nokogiri (>= 1.8.5)
43
+ actionview (6.0.2.2)
44
+ activesupport (= 6.0.2.2)
45
+ builder (~> 3.1)
46
+ erubi (~> 1.4)
47
+ rails-dom-testing (~> 2.0)
48
+ rails-html-sanitizer (~> 1.1, >= 1.2.0)
49
+ activejob (6.0.2.2)
50
+ activesupport (= 6.0.2.2)
51
+ globalid (>= 0.3.6)
13
52
  activemodel (6.0.2.2)
14
53
  activesupport (= 6.0.2.2)
54
+ activerecord (6.0.2.2)
55
+ activemodel (= 6.0.2.2)
56
+ activesupport (= 6.0.2.2)
57
+ activestorage (6.0.2.2)
58
+ actionpack (= 6.0.2.2)
59
+ activejob (= 6.0.2.2)
60
+ activerecord (= 6.0.2.2)
61
+ marcel (~> 0.3.1)
15
62
  activesupport (6.0.2.2)
16
63
  concurrent-ruby (~> 1.0, >= 1.0.2)
17
64
  i18n (>= 0.7, < 2)
@@ -19,7 +66,10 @@ GEM
19
66
  tzinfo (~> 1.1)
20
67
  zeitwerk (~> 2.2)
21
68
  ast (2.4.0)
69
+ builder (3.2.4)
70
+ coderay (1.1.2)
22
71
  concurrent-ruby (1.1.6)
72
+ crass (1.0.6)
23
73
  diff-lcs (1.3)
24
74
  docile (1.3.2)
25
75
  dry-core (0.4.9)
@@ -30,14 +80,63 @@ GEM
30
80
  concurrent-ruby (~> 1.0)
31
81
  dry-core (~> 0.4, >= 0.4.4)
32
82
  dry-equalizer
83
+ erubi (1.9.0)
84
+ globalid (0.4.2)
85
+ activesupport (>= 4.2.0)
33
86
  i18n (1.8.2)
34
87
  concurrent-ruby (~> 1.0)
35
88
  jaro_winkler (1.5.4)
36
89
  json (2.3.0)
90
+ loofah (2.5.0)
91
+ crass (~> 1.0.2)
92
+ nokogiri (>= 1.5.9)
93
+ mail (2.7.1)
94
+ mini_mime (>= 0.1.1)
95
+ marcel (0.3.3)
96
+ mimemagic (~> 0.3.2)
97
+ method_source (0.9.2)
98
+ mimemagic (0.3.4)
99
+ mini_mime (1.0.2)
100
+ mini_portile2 (2.4.0)
37
101
  minitest (5.14.0)
102
+ nio4r (2.5.2)
103
+ nokogiri (1.10.9)
104
+ mini_portile2 (~> 2.4.0)
38
105
  parallel (1.19.1)
39
106
  parser (2.7.1.1)
40
107
  ast (~> 2.4.0)
108
+ pry (0.12.2)
109
+ coderay (~> 1.1.0)
110
+ method_source (~> 0.9.0)
111
+ rack (2.2.2)
112
+ rack-test (1.1.0)
113
+ rack (>= 1.0, < 3)
114
+ rails (6.0.2.2)
115
+ actioncable (= 6.0.2.2)
116
+ actionmailbox (= 6.0.2.2)
117
+ actionmailer (= 6.0.2.2)
118
+ actionpack (= 6.0.2.2)
119
+ actiontext (= 6.0.2.2)
120
+ actionview (= 6.0.2.2)
121
+ activejob (= 6.0.2.2)
122
+ activemodel (= 6.0.2.2)
123
+ activerecord (= 6.0.2.2)
124
+ activestorage (= 6.0.2.2)
125
+ activesupport (= 6.0.2.2)
126
+ bundler (>= 1.3.0)
127
+ railties (= 6.0.2.2)
128
+ sprockets-rails (>= 2.0.0)
129
+ rails-dom-testing (2.0.3)
130
+ activesupport (>= 4.2.0)
131
+ nokogiri (>= 1.6)
132
+ rails-html-sanitizer (1.3.0)
133
+ loofah (~> 2.3)
134
+ railties (6.0.2.2)
135
+ actionpack (= 6.0.2.2)
136
+ activesupport (= 6.0.2.2)
137
+ method_source
138
+ rake (>= 0.8.7)
139
+ thor (>= 0.20.3, < 2.0)
41
140
  rainbow (3.0.0)
42
141
  rake (12.3.3)
43
142
  rexml (3.2.4)
@@ -70,10 +169,21 @@ GEM
70
169
  json (>= 1.8, < 3)
71
170
  simplecov-html (~> 0.10.0)
72
171
  simplecov-html (0.10.2)
172
+ sprockets (4.0.0)
173
+ concurrent-ruby (~> 1.0)
174
+ rack (> 1, < 3)
175
+ sprockets-rails (3.2.1)
176
+ actionpack (>= 4.0)
177
+ activesupport (>= 4.0)
178
+ sprockets (>= 3.0.0)
179
+ thor (1.0.1)
73
180
  thread_safe (0.3.6)
74
181
  tzinfo (1.2.7)
75
182
  thread_safe (~> 0.1)
76
183
  unicode-display_width (1.7.0)
184
+ websocket-driver (0.7.1)
185
+ websocket-extensions (>= 0.1.0)
186
+ websocket-extensions (0.1.4)
77
187
  zeitwerk (2.3.0)
78
188
 
79
189
  PLATFORMS
@@ -81,6 +191,8 @@ PLATFORMS
81
191
 
82
192
  DEPENDENCIES
83
193
  g2_command!
194
+ pry
195
+ rails
84
196
  rake (~> 12.0)
85
197
  rspec (~> 3.0)
86
198
  rubocop
@@ -1,9 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'active_support/core_ext/string'
3
4
  require 'active_model'
4
5
  require 'dry-initializer'
5
6
  require 'dry-monads'
6
7
 
8
+ require 'command/input_middleware'
7
9
  require 'command/interrupt'
8
10
 
9
11
  module Command
@@ -44,12 +46,18 @@ module Command
44
46
  end
45
47
 
46
48
  class_methods do
47
- def run(*args)
48
- new(*args).run
49
+ def run(inputs = {})
50
+ new(normalize_inputs(inputs)).run
49
51
  end
50
52
 
51
- def run!(*args)
52
- run(*args).value!
53
+ def run!(inputs = {})
54
+ run(inputs).value!
55
+ end
56
+
57
+ private
58
+
59
+ def normalize_inputs(inputs)
60
+ Command::InputMiddleware.call(inputs)
53
61
  end
54
62
  end
55
63
  end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'command/input_middleware/rails_params'
4
+ require 'command/input_middleware/symbolizer'
5
+
6
+ module Command
7
+ module InputMiddleware
8
+ MIDDLEWARE = [RailsParams, Symbolizer].freeze
9
+
10
+ def self.call(inputs)
11
+ MIDDLEWARE.reduce(inputs) { |memo, middleware| middleware.call(memo) }
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Command
4
+ module InputMiddleware
5
+ class RailsParams
6
+ def self.call(inputs)
7
+ class_name = 'ActionController::Parameters'
8
+ klass = class_name.safe_constantize
9
+
10
+ return inputs unless klass && inputs.is_a?(klass)
11
+
12
+ inputs.to_unsafe_h.to_h
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_support/core_ext/hash'
4
+
5
+ module Command
6
+ module InputMiddleware
7
+ class Symbolizer
8
+ def self.call(inputs)
9
+ return inputs unless inputs.is_a?(Hash)
10
+
11
+ inputs.to_h.deep_symbolize_keys
12
+ end
13
+ end
14
+ end
15
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Command
4
- VERSION = '0.1.0'
4
+ VERSION = '0.2.0'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: g2_command
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hamed Asghari
@@ -100,6 +100,9 @@ files:
100
100
  - bin/setup
101
101
  - g2_command.gemspec
102
102
  - lib/command.rb
103
+ - lib/command/input_middleware.rb
104
+ - lib/command/input_middleware/rails_params.rb
105
+ - lib/command/input_middleware/symbolizer.rb
103
106
  - lib/command/interrupt.rb
104
107
  - lib/command/version.rb
105
108
  - lib/g2_command.rb