bottled_services 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
+ SHA1:
3
+ metadata.gz: 3ee99318e9f6673bf678f155296d389fb1b39c25
4
+ data.tar.gz: db7d342594ea8fe7f50c3fb54de67625bf9a1977
5
+ SHA512:
6
+ metadata.gz: f63405261144e235bb5432f1fca8e1c01eef538570790fdcf9dde9f40fe6bee667a214f5a7fe97b42568894ae21f9c88ba7332447c00cfa0c4218c79cbf19c22
7
+ data.tar.gz: 9775ee14918fb958a967360be9360f636d3686ffe6531233cf1823b0da4a2b60d2a6def50e6aee77c8196c46f083a24cd68d6456bf165a2217ead42bdd2a5420
@@ -0,0 +1,60 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ *.gem
12
+ *.rbc
13
+ /.config
14
+ /coverage/
15
+ /InstalledFiles
16
+ /pkg/
17
+ /spec/reports/
18
+ /spec/examples.txt
19
+ /test/tmp/
20
+ /test/version_tmp/
21
+ /tmp/
22
+
23
+ # Used by dotenv library to load environment variables.
24
+ # .env
25
+
26
+ ## Specific to RubyMotion:
27
+ .dat*
28
+ .repl_history
29
+ build/
30
+ *.bridgesupport
31
+ build-iPhoneOS/
32
+ build-iPhoneSimulator/
33
+
34
+ ## Specific to RubyMotion (use of CocoaPods):
35
+ #
36
+ # We recommend against adding the Pods directory to your .gitignore. However
37
+ # you should judge for yourself, the pros and cons are mentioned at:
38
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
39
+ #
40
+ # vendor/Pods/
41
+
42
+ ## Documentation cache and generated files:
43
+ /.yardoc/
44
+ /_yardoc/
45
+ /doc/
46
+ /rdoc/
47
+
48
+ ## Environment normalization:
49
+ /.bundle/
50
+ /vendor/bundle
51
+ /lib/bundler/man/
52
+
53
+ # for a library or gem, you might want to ignore these files since the code is
54
+ # intended to run in multiple environments; otherwise, check them in:
55
+ # Gemfile.lock
56
+ # .ruby-version
57
+ # .ruby-gemset
58
+
59
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
60
+ .rvmrc
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.13.6
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at john.hayes.reed@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in bottled_services.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2016 John Hayes-Reed
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 all
13
+ 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 THE
21
+ SOFTWARE.
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 John_Hayes-Reed
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,90 @@
1
+ # BottledServices
2
+
3
+ ## Installation
4
+
5
+ Add this line to your application's Gemfile:
6
+
7
+ ```ruby
8
+ gem 'bottled_services'
9
+ ```
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install bottled_services
18
+
19
+ ## Usage
20
+
21
+ Service Objects can be generated using the bottled_service generator:
22
+
23
+ $ rails g bottled_service ExampleService first_attribute:String second_attribute:Array
24
+
25
+ This will then create a service object that can accept two type-strict attributes, this service can then be called and executed by calling the class call method:
26
+
27
+ ```ruby
28
+ ExampleService.(first_attribute: 'This is a string.', second_attribute: ['This', 'is', 'an', 'Array'])
29
+ ```
30
+ or :
31
+ ```ruby
32
+ ExampleService.(some_valid_params)
33
+ ```
34
+
35
+ Bottled Services provide the ability to create strict-type attributes, however this is not a definite, and in the case of wanting to use type agnostic attributes, just leave out the type from the command:
36
+
37
+ $ rails g bottled_service TypeAgnosticService first_attribute second_attribute
38
+
39
+ when using the generator, the attribute arguments add:
40
+ ```ruby
41
+ att :first_attribute, String
42
+ att :second_attribute, Array
43
+ ```
44
+
45
+ Into the service class which, tells the bottled service which attributes are acceptable, and the type for it. So when not using the generator, or when adding attributes later on, just add another line like the above to declare it.
46
+ And for any type, just leave out the type:
47
+
48
+ ```ruby
49
+ att :third_attribute
50
+ ```
51
+
52
+ Afterwards just add the logic to your new service's call method, and its ready to go:
53
+
54
+ ```ruby
55
+ def call
56
+ puts "My first attribute: #{@first_attribute}"
57
+ end
58
+ ```
59
+
60
+ Bonus!
61
+
62
+ When you generate the service you will notice in the auto-generated call method there is a yield statement:
63
+
64
+ ```ruby
65
+ def call
66
+ # Do something...
67
+ yield if block_given?
68
+ end
69
+ ```
70
+
71
+ Bottled Services can accept blocks for those rare times when you want to run the service logic, but need a little something extra that you don't want to have to put in your controller logic, or have to write another service for, just pass the block in when initiating with the class call method, and it will be available to yield from your service instances call method:
72
+
73
+ ```ruby
74
+ ExampleService.(some_valid_params){|first_att, second_att| puts "All the atts! #{first_att}, #{second_att}" }
75
+ ```
76
+
77
+ ## Development
78
+
79
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
80
+
81
+ 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).
82
+
83
+ ## Contributing
84
+
85
+ Bug reports and pull requests are welcome on GitHub at https://github.com/John-Hayes-Reed/bottled_services. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
86
+
87
+
88
+ ## License
89
+
90
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "bottled_services"
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
@@ -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,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'bottled_services/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "bottled_services"
8
+ spec.version = BottledServices::VERSION
9
+ spec.authors = ["John_Hayes-Reed"]
10
+ spec.email = ["john.hayes.reed@gmail.com"]
11
+
12
+ spec.summary = %q{A gourmet service object}
13
+ spec.description = %q{This gem provides Class to be the base for services and a generator to easily create them.}
14
+ spec.homepage = "https://github.com/John-Hayes-Reed/bottled_services"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.13"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "rspec", "~> 3.0"
27
+ end
@@ -0,0 +1,4 @@
1
+ require 'bottled_services/version'
2
+ require 'bottled_services/bottled_service'
3
+ class BottledServices
4
+ end
@@ -0,0 +1,34 @@
1
+ class BottledService
2
+ def self.att(att_key, type=nil)
3
+ unless type.nil?
4
+ define_method "#{att_key}=" do |value|
5
+ raise IllegalTypeError unless value.is_a?(type)
6
+ instance_variable_set "@#{att_key}", value
7
+ end
8
+ else
9
+ define_method "#{att_key}=" do |value|
10
+ instance_variable_set "@#{att_key}", value
11
+ end
12
+ end
13
+ define_method att_key do
14
+ instance_variable_get "@#{att_key}"
15
+ end
16
+ end
17
+
18
+ def self.call(**atts)
19
+ if block_given?
20
+ new(**atts).(&Proc.new)
21
+ else
22
+ new(**atts).()
23
+ end
24
+ end
25
+
26
+ def initialize(**atts)
27
+ atts.each do |key, value|
28
+ self.send("#{key}=", value)
29
+ end
30
+ end
31
+
32
+ class BottledServiceError < StandardError; end
33
+ class IllegalTypeError < BottledServiceError; end
34
+ end
@@ -0,0 +1,3 @@
1
+ class BottledServices
2
+ VERSION = "0.1.3"
3
+ end
@@ -0,0 +1,33 @@
1
+ require 'rails/generators'
2
+ class BottledServiceGenerator < Rails::Generators::NamedBase
3
+ source_root File.expand_path('../templates', __FILE__)
4
+ argument :attributes, type: :array, default: []
5
+
6
+ def generate_bottled_service
7
+ puts "Generating Bottled Service: #{name}"
8
+ create_file "app/services/#{file_name}.rb", <<-File
9
+ class #{class_name} < BottledService
10
+
11
+ #{ "".tap do |str|
12
+ attributes.each do |attribute|
13
+ puts "injecting attribute: #{attribute.name}"
14
+ if attribute.type.present?
15
+ str << "att :#{attribute.name}, #{attribute.type}
16
+ "
17
+ else
18
+ str << "att :#{attribute.name}
19
+ "
20
+ end
21
+ end
22
+ end
23
+ }
24
+
25
+ def call
26
+ # Do something...
27
+ yield if block_given?
28
+ end
29
+
30
+ end
31
+ File
32
+ end
33
+ end
metadata ADDED
@@ -0,0 +1,103 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bottled_services
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.3
5
+ platform: ruby
6
+ authors:
7
+ - John_Hayes-Reed
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-11-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.13'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.13'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description: This gem provides Class to be the base for services and a generator to
56
+ easily create them.
57
+ email:
58
+ - john.hayes.reed@gmail.com
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - ".rspec"
65
+ - ".travis.yml"
66
+ - CODE_OF_CONDUCT.md
67
+ - Gemfile
68
+ - LICENSE
69
+ - LICENSE.txt
70
+ - README.md
71
+ - Rakefile
72
+ - bin/console
73
+ - bin/setup
74
+ - bottled_services.gemspec
75
+ - lib/bottled_services.rb
76
+ - lib/bottled_services/bottled_service.rb
77
+ - lib/bottled_services/version.rb
78
+ - lib/generators/bottled_service/bottled_service_generator.rb
79
+ homepage: https://github.com/John-Hayes-Reed/bottled_services
80
+ licenses:
81
+ - MIT
82
+ metadata: {}
83
+ post_install_message:
84
+ rdoc_options: []
85
+ require_paths:
86
+ - lib
87
+ required_ruby_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ requirements: []
98
+ rubyforge_project:
99
+ rubygems_version: 2.5.1
100
+ signing_key:
101
+ specification_version: 4
102
+ summary: A gourmet service object
103
+ test_files: []