simple-service 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 5300b67f8c93b974d4ae19f285aa80915b195f8c5483c340b1716ecf2b41f969
4
+ data.tar.gz: 4272fc5ea6add6f0bb774c7faee8d2abe00ad0f1bda1056b80cc3a57a9ab6df5
5
+ SHA512:
6
+ metadata.gz: 83233c349d6a144183f0ca2a18993712a4902dcc65934a63dcc7cfed370ffc1ddcdfa7754a1ffff85f11c8875007de7843f8c5d7fd8d6f7eb799dd14c1e3b373
7
+ data.tar.gz: '0268ef5da51bcca27e9a3a1766f9ede7d67a8213cf52b97206d000836012cd7c3220511098dad734c316fa3a068f3e853301ffaf8b8dac73712b3f3757dd674b'
@@ -0,0 +1,12 @@
1
+ coverage
2
+ rdoc
3
+ pkg
4
+ log/*.log
5
+ .rspec.data
6
+ Gemfile.lock
7
+ .rake_t_cache
8
+ .rspec.status
9
+ .DS_Store
10
+ tmp
11
+ .byebug_history
12
+ .bundle/config
@@ -0,0 +1,100 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.3
3
+ Exclude:
4
+ - 'spec/**/*'
5
+ - 'test/**/*'
6
+ - 'bin/**/*'
7
+ - 'tasks/release.rake'
8
+ - '*.gemspec'
9
+ - 'Gemfile'
10
+ - 'Rakefile'
11
+ - 'scripts/*.rb'
12
+
13
+ Metrics/BlockLength:
14
+ Exclude:
15
+ - 'spec/**/*'
16
+
17
+ Metrics/LineLength:
18
+ Max: 140
19
+
20
+ Metrics/MethodLength:
21
+ Max: 20
22
+
23
+ Style/SpecialGlobalVars:
24
+ Enabled: false
25
+
26
+ Style/StringLiterals:
27
+ EnforcedStyle: double_quotes
28
+ ConsistentQuotesInMultiline: false
29
+
30
+ Style/ClassAndModuleChildren:
31
+ Enabled: false
32
+
33
+ Style/ModuleFunction:
34
+ Enabled: false
35
+
36
+ Style/FrozenStringLiteralComment:
37
+ Enabled: false
38
+
39
+ Style/Documentation:
40
+ Enabled: false
41
+
42
+ Style/MutableConstant:
43
+ Enabled: false
44
+
45
+ Style/FormatStringToken:
46
+ Enabled: false
47
+
48
+ Style/Lambda:
49
+ Enabled: false
50
+
51
+ Style/SymbolArray:
52
+ Enabled: false
53
+
54
+ Style/FormatString:
55
+ Enabled: false
56
+
57
+ Style/PercentLiteralDelimiters:
58
+ Enabled: false
59
+
60
+ Lint/MissingCopEnableDirective:
61
+ Enabled: false
62
+
63
+ Style/NumericPredicate:
64
+ Enabled: false
65
+
66
+ Style/RegexpLiteral:
67
+ Enabled: false
68
+
69
+ Style/ClassVars:
70
+ Enabled: false
71
+
72
+ Style/ConditionalAssignment:
73
+ Enabled: false
74
+
75
+ Style/IfUnlessModifier:
76
+ Enabled: false
77
+
78
+ Style/PerlBackrefs:
79
+ Enabled: false
80
+
81
+ Style/TrailingUnderscoreVariable:
82
+ Enabled: false
83
+
84
+ Style/StderrPuts:
85
+ Enabled: false
86
+
87
+ Style/NonNilCheck:
88
+ Enabled: false
89
+
90
+ Metrics/ParameterLists:
91
+ Enabled: false
92
+
93
+ Style/StringLiteralsInInterpolation:
94
+ Enabled: false
95
+
96
+ Style/DoubleNegation:
97
+ Enabled: false
98
+
99
+ Style/ParallelAssignment:
100
+ Enabled: false
@@ -0,0 +1 @@
1
+ excludeDirectories = "{_build,coverage,rdoc,assets/node_modules,node_modules,deps,db,cover,priv/static,storage,github,vendor,arena,}"
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in {gemname}.gemspec
4
+ gemspec
5
+
6
+ # --- Development and test dependencies ------------------------------
7
+
8
+ group :development, :test do
9
+ gem 'rake', '~> 11'
10
+ gem 'rspec', '~> 3.7'
11
+ # gem 'rubocop', '~> 0.61.1'
12
+ gem 'simplecov', '~> 0'
13
+ gem 'byebug'
14
+ end
@@ -0,0 +1,16 @@
1
+ .PHONY: test
2
+
3
+ test:
4
+ rspec
5
+
6
+ .PHONY: doc doc/rdoc
7
+ doc: doc/rdoc
8
+
9
+ doc/rdoc:
10
+ rm -rf doc/rdoc
11
+ rdoc -o doc/rdoc README.md \
12
+ lib/simple/service.rb \
13
+ lib/simple/service/action.rb \
14
+ lib/simple/service/context.rb \
15
+ lib/simple/service/errors.rb \
16
+ lib/simple/service/version.rb
@@ -0,0 +1,3 @@
1
+ # simple-service – a pretty simple and somewhat abstract service description
2
+
3
+ Yea, that's it.
@@ -0,0 +1,6 @@
1
+ Dir.glob("tasks/*.rake").each { |r| import r }
2
+
3
+ task :release do
4
+ sh "scripts/release"
5
+ end
6
+
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.3
@@ -0,0 +1,105 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'bundle' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require "rubygems"
12
+
13
+ m = Module.new do
14
+ module_function
15
+
16
+ def invoked_as_script?
17
+ File.expand_path($0) == File.expand_path(__FILE__)
18
+ end
19
+
20
+ def env_var_version
21
+ ENV["BUNDLER_VERSION"]
22
+ end
23
+
24
+ def cli_arg_version
25
+ return unless invoked_as_script? # don't want to hijack other binstubs
26
+ return unless "update".start_with?(ARGV.first || " ") # must be running `bundle update`
27
+ bundler_version = nil
28
+ update_index = nil
29
+ ARGV.each_with_index do |a, i|
30
+ if update_index && update_index.succ == i && a =~ Gem::Version::ANCHORED_VERSION_PATTERN
31
+ bundler_version = a
32
+ end
33
+ next unless a =~ /\A--bundler(?:[= ](#{Gem::Version::VERSION_PATTERN}))?\z/
34
+ bundler_version = $1 || ">= 0.a"
35
+ update_index = i
36
+ end
37
+ bundler_version
38
+ end
39
+
40
+ def gemfile
41
+ gemfile = ENV["BUNDLE_GEMFILE"]
42
+ return gemfile if gemfile && !gemfile.empty?
43
+
44
+ File.expand_path("../../Gemfile", __FILE__)
45
+ end
46
+
47
+ def lockfile
48
+ lockfile =
49
+ case File.basename(gemfile)
50
+ when "gems.rb" then gemfile.sub(/\.rb$/, gemfile)
51
+ else "#{gemfile}.lock"
52
+ end
53
+ File.expand_path(lockfile)
54
+ end
55
+
56
+ def lockfile_version
57
+ return unless File.file?(lockfile)
58
+ lockfile_contents = File.read(lockfile)
59
+ return unless lockfile_contents =~ /\n\nBUNDLED WITH\n\s{2,}(#{Gem::Version::VERSION_PATTERN})\n/
60
+ Regexp.last_match(1)
61
+ end
62
+
63
+ def bundler_version
64
+ @bundler_version ||= begin
65
+ env_var_version || cli_arg_version ||
66
+ lockfile_version || "#{Gem::Requirement.default}.a"
67
+ end
68
+ end
69
+
70
+ def load_bundler!
71
+ ENV["BUNDLE_GEMFILE"] ||= gemfile
72
+
73
+ # must dup string for RG < 1.8 compatibility
74
+ activate_bundler(bundler_version.dup)
75
+ end
76
+
77
+ def activate_bundler(bundler_version)
78
+ if Gem::Version.correct?(bundler_version) && Gem::Version.new(bundler_version).release < Gem::Version.new("2.0")
79
+ bundler_version = "< 2"
80
+ end
81
+ gem_error = activation_error_handling do
82
+ gem "bundler", bundler_version
83
+ end
84
+ return if gem_error.nil?
85
+ require_error = activation_error_handling do
86
+ require "bundler/version"
87
+ end
88
+ return if require_error.nil? && Gem::Requirement.new(bundler_version).satisfied_by?(Gem::Version.new(Bundler::VERSION))
89
+ warn "Activating bundler (#{bundler_version}) failed:\n#{gem_error.message}\n\nTo install the version of bundler this project requires, run `gem install bundler -v '#{bundler_version}'`"
90
+ exit 42
91
+ end
92
+
93
+ def activation_error_handling
94
+ yield
95
+ nil
96
+ rescue StandardError, LoadError => e
97
+ e
98
+ end
99
+ end
100
+
101
+ m.load_bundler!
102
+
103
+ if m.invoked_as_script?
104
+ load Gem.bin_path("bundler", "bundle")
105
+ end
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ Bundler.require
5
+ require "simple-service"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'rake' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require "pathname"
12
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
+ Pathname.new(__FILE__).realpath)
14
+
15
+ bundle_binstub = File.expand_path("../bundle", __FILE__)
16
+
17
+ if File.file?(bundle_binstub)
18
+ if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19
+ load(bundle_binstub)
20
+ else
21
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
+ end
24
+ end
25
+
26
+ require "rubygems"
27
+ require "bundler/setup"
28
+
29
+ load Gem.bin_path("rake", "rake")
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'rspec' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require "pathname"
12
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
+ Pathname.new(__FILE__).realpath)
14
+
15
+ bundle_binstub = File.expand_path("../bundle", __FILE__)
16
+
17
+ if File.file?(bundle_binstub)
18
+ if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19
+ load(bundle_binstub)
20
+ else
21
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
+ end
24
+ end
25
+
26
+ require "rubygems"
27
+ require "bundler/setup"
28
+
29
+ load Gem.bin_path("rspec-core", "rspec")
@@ -0,0 +1,3 @@
1
+ # rubocop:disable Naming/FileName
2
+
3
+ require "simple/service"
@@ -0,0 +1,103 @@
1
+ module Simple # :nodoc:
2
+ end
3
+
4
+ require "expectation"
5
+
6
+ require_relative "service/errors"
7
+ require_relative "service/action"
8
+ require_relative "service/context"
9
+ require_relative "service/version"
10
+
11
+ # The Simple::Service module.
12
+ #
13
+ # To mark a target module as a service module one must include the
14
+ # Simple::Service module into the target module.
15
+ #
16
+ # This serves as a marker that this module is actually intended
17
+ # to be used as a service.
18
+ module Simple::Service
19
+ def self.included(klass) # :nodoc:
20
+ klass.extend ClassMethods
21
+ end
22
+
23
+ # returns true if the passed in object is a service module.
24
+ def self.service?(service)
25
+ service.is_a?(Module) && service.include?(self)
26
+ end
27
+
28
+ def self.verify_service!(service) # :nodoc:
29
+ raise ::ArgumentError, "#{service.inspect} must be a Simple::Service, but is not even a Module" unless service.is_a?(Module)
30
+ raise ::ArgumentError, "#{service.inspect} must be a Simple::Service, did you 'include Simple::Service'" unless service?(service)
31
+ end
32
+
33
+ # returns a Hash with all actions in the +service+ module
34
+ def self.actions(service)
35
+ verify_service!(service)
36
+
37
+ service.__simple_service_actions__
38
+ end
39
+
40
+ # returns the action with the given name.
41
+ def self.action(service, name)
42
+ actions = self.actions(service)
43
+ actions[name] || begin
44
+ raise ::Simple::Service::NoSuchAction.new(service, name)
45
+ end
46
+ end
47
+
48
+ # invokes an action with a given +name+ in a service with +arguments+ and +params+.
49
+ #
50
+ # You cannot call this method if the context is not set.
51
+ #
52
+ # When calling #invoke using positional arguments they will be matched against
53
+ # positional arguments of the invoked method - but they will not be matched
54
+ # against named arguments.
55
+ #
56
+ # When there are not enough positional arguments to match the number of required
57
+ # positional arguments of the method we raise an ArgumentError.
58
+ #
59
+ # When there are more positional arguments provided than the number accepted
60
+ # by the method we raise an ArgumentError.
61
+ #
62
+ # Entries in the named_args Hash that are not defined in the action itself are ignored.
63
+ def self.invoke(service, name, *args, **named_args)
64
+ raise ContextMissingError, "Need to set context before calling ::Simple::Service.invoke" unless context
65
+
66
+ action(service, name).invoke(*args, **named_args)
67
+ end
68
+
69
+ # invokes an action with a given +name+ in a service with a Hash of arguments.
70
+ #
71
+ # You cannot call this method if the context is not set.
72
+ def self.invoke2(service, name, args: {}, flags: {})
73
+ raise ContextMissingError, "Need to set context before calling ::Simple::Service.invoke" unless context
74
+
75
+ action(service, name).invoke2(args: args, flags: flags)
76
+ end
77
+
78
+ module ClassMethods # :nodoc:
79
+ # returns a Hash of actions provided by the service module.
80
+ def __simple_service_actions__
81
+ @__simple_service_actions__ ||= Action.enumerate(service: self)
82
+ end
83
+ end
84
+
85
+ # # Resolves a service by name. Returns nil if the name does not refer to a service,
86
+ # # or the service module otherwise.
87
+ # def self.resolve(str)
88
+ # return unless str =~ /^[A-Z][A-Za-z0-9_]*(::[A-Z][A-Za-z0-9_]*)*$/
89
+ #
90
+ # service = resolve_constant(str)
91
+ #
92
+ # return unless service.is_a?(Module)
93
+ # return unless service.include?(::Simple::Service)
94
+ #
95
+ # service
96
+ # end
97
+ #
98
+ # def self.resolve_constant(str)
99
+ # const_get(str)
100
+ # rescue NameError
101
+ # nil
102
+ # end
103
+ end