excom 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cf41e297a57b63652c79c3455846ceef0398f1ea
4
- data.tar.gz: 27447ccbbcee3505e65f4a7d78908437f7197d6a
3
+ metadata.gz: 0e2a4c4c2e30de13e0b49be35a9f54a798b902b5
4
+ data.tar.gz: c415fda36ef08ab72a157917717ab217a7033ae5
5
5
  SHA512:
6
- metadata.gz: 3cbfb293d339f11984aab4b78f86ad1b93f70ba0721dbabcaecd4e175a8ec56bc8ffb583fcf88b2256cd85abc83f1e386c9ec5015acb4e6b16a5eff4437689d8
7
- data.tar.gz: 994147da0552e012f35bed28e7c19933f06ea1a88e28cef013d8869a8a9d4cbf9bd1b7d3b59c86584ea9b6c62bf3a698bfd8c03f83d63cc6c3267e728ef93e8e
6
+ metadata.gz: 36cbeb14f6e1c366446787ea8c5b7475197180dd30bd99d8842328cd20071db59cabefb8dd2c9c390addd4040e7588b5a9484509a433eb156b70a10ab5700db4
7
+ data.tar.gz: c5d76e81aff3acbda0f7c28059f20ae46f778b465771ab52b2bbc04b46116e218a045a7982a0a36aeb8ab88fdb00d4033ebd9e2ec9ef7acacdf1e216fe20d26d
data/README.md CHANGED
@@ -224,6 +224,9 @@ end
224
224
  - [`:assertions`](https://github.com/akuzko/excom/wiki/Plugins#assertions) - Provides `assert` method that
225
225
  can be used for different logic checks during command execution.
226
226
 
227
+ - [`:dry_types`](https://github.com/akuzko/excom/wiki/Plugins#dry-types) - Allows you to use
228
+ [dry-types](http://dry-rb.org/gems/dry-types/) attributes instead of default `args` and `opts`.
229
+
227
230
  - [`:caching`](https://github.com/akuzko/excom/wiki/Plugins#caching) - Simple plugin that will prevent
228
231
  re-execution of command if it already has been executed, and will immediately return result.
229
232
 
data/bin/console CHANGED
@@ -8,8 +8,9 @@ Excom::Sentry.deny_with :unauthorized
8
8
  class Show < Excom::Command
9
9
  use :sentry, class: 'MySentry'
10
10
  use :caching
11
+ use :dry_types
11
12
 
12
- args :foo
13
+ attribute :foo, Dry::Types['int']
13
14
 
14
15
  def run
15
16
  {foo: foo}
data/excom.gemspec CHANGED
@@ -23,6 +23,8 @@ Gem::Specification.new do |spec|
23
23
 
24
24
  spec.add_development_dependency "bundler", "~> 1.11"
25
25
  spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "dry-types", "~> 0.12"
27
+ spec.add_development_dependency "dry-struct", "~> 0.4"
26
28
  spec.add_development_dependency "rspec", "~> 3.0"
27
29
  spec.add_development_dependency "rspec-its", "~> 1.2"
28
30
  spec.add_development_dependency "pry"
@@ -14,8 +14,8 @@ module Excom
14
14
 
15
15
  def initialize_clone(*)
16
16
  super
17
- @args = @args.dup
18
- @opts = @opts.dup
17
+ @args = @args.dup unless @args.nil?
18
+ @opts = @opts.dup unless @opts.nil?
19
19
  end
20
20
 
21
21
  def with_args(*args)
@@ -0,0 +1,70 @@
1
+ module Excom
2
+ module Plugins::DryTypes
3
+ Plugins.register :dry_types, self
4
+
5
+ attr_accessor :attributes
6
+ protected :attributes=
7
+
8
+ def self.used(command_class, *)
9
+ require 'dry-types'
10
+ require 'dry-struct'
11
+
12
+ command_class.const_set(:Attributes, Class.new(Dry::Struct))
13
+ end
14
+
15
+ def initialize(attrs)
16
+ @attributes = self.class::Attributes.new(attrs)
17
+
18
+ super
19
+ end
20
+
21
+ def initialize_clone(*)
22
+ @attributes = @attributes.dup
23
+ super
24
+ end
25
+
26
+ def with_attributes(attrs)
27
+ clone.tap do |copy|
28
+ copy.attributes = self.class::Attributes.new(attributes.to_hash.merge(attrs))
29
+ end
30
+ end
31
+
32
+ # args and opts overloads
33
+ private def resolve_args!(args)
34
+ [nil, nil]
35
+ end
36
+
37
+ private def assert_valid_args!(*)
38
+ end
39
+
40
+ private def assert_valid_opts!(*)
41
+ end
42
+
43
+ def with_args(*)
44
+ fail "`with_args' method is not available with :dry_types plugin. use `with_attributes' method instead"
45
+ end
46
+
47
+ def with_opts(*)
48
+ fail "`with_opts' method is not available with :dry_types plugin. use `with_attributes' method instead"
49
+ end
50
+
51
+ module ClassMethods
52
+ def args(*)
53
+ fail "`args' method is not available with :dry_types plugin. use `attribute' method instead"
54
+ end
55
+
56
+ def opts(*)
57
+ fail "`args' method is not available with :dry_types plugin. use `attribute' method instead"
58
+ end
59
+
60
+ def attribute(name, *args)
61
+ const_get(:Attributes).send(:attribute, name, *args)
62
+ arg_methods.send(:define_method, name){ @attributes.send(name) }
63
+ end
64
+
65
+ def constructor_type(*args)
66
+ const_get(:Attributes).send(:constructor_type, *args)
67
+ end
68
+ end
69
+ end
70
+ end
@@ -2,9 +2,6 @@ module Excom
2
2
  module Plugins::Executable
3
3
  Plugins.register :executable, self
4
4
 
5
- UNDEFINED = :__EXCOM_UNDEFINED__
6
- private_constant :UNDEFINED
7
-
8
5
  Result = Struct.new(:status, :result)
9
6
 
10
7
  def initialize(*)
@@ -44,8 +44,8 @@ module Excom
44
44
  command_class.sentry_class(_sentry_class)
45
45
  end
46
46
 
47
- def sentry_class(klass = nil)
48
- return self._sentry_class = klass unless klass.nil?
47
+ def sentry_class(klass = UNDEFINED)
48
+ return self._sentry_class = klass unless klass == UNDEFINED
49
49
  return @sentry_class if defined? @sentry_class
50
50
 
51
51
  @sentry_class =
data/lib/excom/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Excom
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
3
3
  end
data/lib/excom.rb CHANGED
@@ -7,4 +7,16 @@ module Excom
7
7
  extend Plugins::Context::ExcomMethods
8
8
 
9
9
  Sentry = Plugins::Sentry::Sentinel
10
+
11
+ UNDEFINED = Object.new.tap do |obj|
12
+ def obj.to_s
13
+ 'UNDEFINED'.freeze
14
+ end
15
+
16
+ def obj.inspect
17
+ 'UNDEFINED'.freeze
18
+ end
19
+
20
+ obj.freeze
21
+ end
10
22
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: excom
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Artem Kuzko
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-02-04 00:00:00.000000000 Z
11
+ date: 2018-02-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -38,6 +38,34 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: dry-types
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.12'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.12'
55
+ - !ruby/object:Gem::Dependency
56
+ name: dry-struct
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.4'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.4'
41
69
  - !ruby/object:Gem::Dependency
42
70
  name: rspec
43
71
  requirement: !ruby/object:Gem::Requirement
@@ -119,6 +147,7 @@ files:
119
147
  - lib/excom/plugins/assertions.rb
120
148
  - lib/excom/plugins/caching.rb
121
149
  - lib/excom/plugins/context.rb
150
+ - lib/excom/plugins/dry_types.rb
122
151
  - lib/excom/plugins/executable.rb
123
152
  - lib/excom/plugins/pluggable.rb
124
153
  - lib/excom/plugins/rescue.rb