rails_services 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5413a8f8f97cf858983bacef0211b5f8c07e4c21
4
+ data.tar.gz: 5673400b590f441e5a07c6c30673ec5638555149
5
+ SHA512:
6
+ metadata.gz: c2dbd01c02a5f518be4fa69161b09c9a5be5bc1760434c3602a915fe254130c6e3edec3d0f14c13849f8e9cd45247eaad58a99a551a04cfa3fa9a5d4d42187e1
7
+ data.tar.gz: c611e5527ee7c2c97223f36a64c5b4ced4ec3bc30d9e3311bf627a63c4da4731c9468c0cca5dc14b50c4feda844663fc004cf6d75e317c446ea7e67a227d1201
data/.gitignore ADDED
@@ -0,0 +1,23 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
23
+ .idea
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --warnings
3
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rails_services.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Craig Kaminsky
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,48 @@
1
+ # RailsServices
2
+
3
+ A very (VERY) simple gem for Rails that adds a generator for easily creating a service class and its accompanying spec file.
4
+
5
+ At this time, the gem only creates an RSpec test file. MiniTest and Test::Unit support forthcoming.
6
+
7
+ ## Requirements
8
+
9
+ Rails 3.2.19 and higher
10
+
11
+ ## Installation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ gem 'rails_services'
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install rails_services
24
+
25
+ ## Usage
26
+
27
+ Examples:
28
+
29
+ $ rails generate rails_services:create Service Model|Controller Sub-folder [opt]
30
+
31
+ $ rails generate rails_services:destroy Service Model|Controller Sub-folder [opt]
32
+
33
+ Sub-folders are optional but, at this time, you may only use one sub-folder. I generally use the sub-folders when I have a naturally grouped set of services.
34
+
35
+ ## Result
36
+
37
+ Two files are created:
38
+
39
+ + app/services/model|controller/[sub-folder]/thing.rb
40
+ + spec/services/model|controller/[sub-folder]/thing_spec.rb
41
+
42
+ ## Contributing
43
+
44
+ 1. Fork it ( https://github.com/imageaid/rails_services/fork )
45
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
46
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
47
+ 4. Push to the branch (`git push origin my-new-feature`)
48
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
7
+
8
+ task :console do
9
+ exec 'pry -r rails_services -I ./lib'
10
+ end
11
+
@@ -0,0 +1,9 @@
1
+ Description:
2
+ Generates a service class and accompanying spec file
3
+
4
+ Example:
5
+ rails generate rails_services:create Thing Model|Controller Sub-folder [opt]
6
+
7
+ This will create:
8
+ app/services/model|controller/[sub-folder]/thing.rb
9
+ spec/services/model|controller/[sub-folder]/thing_spec.rb
@@ -0,0 +1,37 @@
1
+ module RailsServices
2
+ module Generators
3
+ class CreateGenerator < Rails::Generators::Base
4
+ source_root File.expand_path('../templates', __FILE__)
5
+ argument :service_name, type: :string
6
+ argument :parent_name, type: :string
7
+ argument :sub_folder, type: :string, default: ''
8
+
9
+ def create_service
10
+ template 'base_service.rb.erb', "app/services/#{service_directory}/#{service_file}"
11
+ template 'base_service_spec.rb.erb', "spec/services/#{service_directory}/#{spec_file}"
12
+ end
13
+
14
+ private
15
+ def service_directory
16
+ file_path = "#{parent_name.underscore}"
17
+ file_path += "/#{sub_folder.underscore}" if sub_folder.present?
18
+ file_path
19
+ end
20
+
21
+ def service_file
22
+ "#{service_name.underscore}.rb"
23
+ end
24
+
25
+ def spec_file
26
+ "#{service_name.underscore}_spec.rb"
27
+ end
28
+
29
+ def qualified_name
30
+ name = "#{parent_name.camelize}::"
31
+ name += "#{sub_folder.camelize}::" if sub_folder.present?
32
+ name += "#{service_name.camelize}"
33
+ name
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,8 @@
1
+ <%= "class #{qualified_name}" %>
2
+
3
+ <%= "# SAMPLE USAGE: #{qualified_name}.call(*args)" %>
4
+ <%= 'def self.call' %>
5
+
6
+ <%= 'end' %>
7
+
8
+ <%= 'end' %>
@@ -0,0 +1,11 @@
1
+ <%= "describe #{qualified_name} do" %>
2
+
3
+ <%= "context 'doing something' do" %>
4
+
5
+ <%= "it 'should test something' do" %>
6
+ <%= 'skip' %>
7
+ <%= 'end' %>
8
+
9
+ <%= 'end' %>
10
+
11
+ <%= 'end' %>
@@ -0,0 +1,9 @@
1
+ Description:
2
+ Destroys a service class and accompanying spec file
3
+
4
+ Example:
5
+ rails generate rails_services:destroy Thing Model|Controller Sub-folder [opt]
6
+
7
+ This will remove:
8
+ app/services/model|controller/[sub-folder]/thing.rb
9
+ spec/services/model|controller/[sub-folder]/thing_spec.rb
@@ -0,0 +1,51 @@
1
+ module RailsServices
2
+ module Generators
3
+ class DestroyGenerator < Rails::Generators::Base
4
+ argument :service_name, type: :string
5
+ argument :parent_name, type: :string
6
+ argument :sub_folder, type: :string, default: ''
7
+
8
+ def destroy_service
9
+ remove_file "app/services/#{full_service_directory}/#{service_file}"
10
+ remove_file "spec/services/#{full_service_directory}/#{spec_file}"
11
+
12
+ manage_containing_directories('app', 'spec')
13
+ end
14
+
15
+ private
16
+ def full_service_directory
17
+ file_path = "#{service_parent_directory}"
18
+ file_path += "/#{sub_folder.underscore}" if sub_folder.present?
19
+ file_path
20
+ end
21
+
22
+ def service_parent_directory
23
+ "#{parent_name.underscore}"
24
+ end
25
+
26
+ def service_file
27
+ "#{service_name.underscore}.rb"
28
+ end
29
+
30
+ def spec_file
31
+ "#{service_name.underscore}_spec.rb"
32
+ end
33
+
34
+ def manage_containing_directories(*directory_types)
35
+ directory_types.each do |directory_type|
36
+ remove_dir("#{directory_type}/services/#{full_service_directory}") if directory_empty?(directory_type)
37
+ remove_dir("#{directory_type}/services/#{service_parent_directory}") if parent_directory_empty?(directory_type)
38
+ end
39
+ end
40
+
41
+ def directory_empty?(directory_type)
42
+ Dir["#{Rails.root}/#{directory_type}/services/#{full_service_directory}/*"].empty?
43
+ end
44
+
45
+ def parent_directory_empty?(directory_type)
46
+ Dir["#{Rails.root}/#{directory_type}/services/#{service_parent_directory}/*"].empty?
47
+ end
48
+
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,10 @@
1
+ require 'rails_services/version'
2
+
3
+ begin
4
+ require 'pry'
5
+ rescue LoadError
6
+ end
7
+
8
+ module RailsServices
9
+ # Your code goes here...
10
+ end
@@ -0,0 +1,3 @@
1
+ module RailsServices
2
+ VERSION = '1.0.0'
3
+ end
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rails_services/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'rails_services'
8
+ spec.version = RailsServices::VERSION
9
+ spec.authors = ['Craig Kaminsky']
10
+ spec.email = ['imageaid@gmail.com']
11
+ spec.summary = %q{A Ruby gem that adds a rails generator for creating service classes.}
12
+ spec.description = %q{Speed up development when using a Service Layer by easily creating service classes and their attending test (spec) file.}
13
+ spec.homepage = 'https://github.com/imageaid/rails_service_generator'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_dependency 'activesupport', '>= 3.2.19'
22
+ spec.add_dependency 'rails', '>= 3.2.19'
23
+
24
+ spec.add_development_dependency 'bundler', '~> 1.6'
25
+ spec.add_development_dependency 'rake'
26
+ spec.add_development_dependency 'rspec'
27
+ spec.add_development_dependency 'pry'
28
+ end
@@ -0,0 +1,5 @@
1
+ describe 'My behaviour' do
2
+ it 'should do something' do
3
+ expect(true).to be_falsey
4
+ end
5
+ end
@@ -0,0 +1,7 @@
1
+ describe 'My behaviour' do
2
+
3
+ it 'should do something' do
4
+ expect(true).to be_falsey
5
+ end
6
+
7
+ end
@@ -0,0 +1,64 @@
1
+ require 'rails_services'
2
+
3
+ RSpec.configure do |config|
4
+ # The settings below are suggested to provide a good initial experience
5
+ # with RSpec, but feel free to customize to your heart's content.
6
+ =begin
7
+ # These two settings work together to allow you to limit a spec run
8
+ # to individual examples or groups you care about by tagging them with
9
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
10
+ # get run.
11
+ config.filter_run :focus
12
+ config.run_all_when_everything_filtered = true
13
+
14
+ # Many RSpec users commonly either run the entire suite or an individual
15
+ # file, and it's useful to allow more verbose output when running an
16
+ # individual spec file.
17
+ if config.files_to_run.one?
18
+ # Use the documentation formatter for detailed output,
19
+ # unless a formatter has already been configured
20
+ # (e.g. via a command-line flag).
21
+ config.default_formatter = 'doc'
22
+ end
23
+
24
+ # Print the 10 slowest examples and example groups at the
25
+ # end of the spec run, to help surface which specs are running
26
+ # particularly slow.
27
+ config.profile_examples = 10
28
+
29
+ # Run specs in random order to surface order dependencies. If you find an
30
+ # order dependency and want to debug it, you can fix the order by providing
31
+ # the seed, which is printed after each run.
32
+ # --seed 1234
33
+ config.order = :random
34
+
35
+ # Seed global randomization in this process using the `--seed` CLI option.
36
+ # Setting this allows you to use `--seed` to deterministically reproduce
37
+ # test failures related to randomization by passing the same `--seed` value
38
+ # as the one that triggered the failure.
39
+ Kernel.srand config.seed
40
+
41
+ # rspec-expectations config goes here. You can use an alternate
42
+ # assertion/expectation library such as wrong or the stdlib/minitest
43
+ # assertions if you prefer.
44
+ config.expect_with :rspec do |expectations|
45
+ # Enable only the newer, non-monkey-patching expect syntax.
46
+ # For more details, see:
47
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
48
+ expectations.syntax = :expect
49
+ end
50
+
51
+ # rspec-mocks config goes here. You can use an alternate test double
52
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
53
+ config.mock_with :rspec do |mocks|
54
+ # Enable only the newer, non-monkey-patching expect syntax.
55
+ # For more details, see:
56
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
57
+ mocks.syntax = :expect
58
+
59
+ # Prevents you from mocking or stubbing a method that does not exist on
60
+ # a real object. This is generally recommended.
61
+ mocks.verify_partial_doubles = true
62
+ end
63
+ =end
64
+ end
metadata ADDED
@@ -0,0 +1,151 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rails_services
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Craig Kaminsky
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-07-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 3.2.19
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 3.2.19
27
+ - !ruby/object:Gem::Dependency
28
+ name: rails
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 3.2.19
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 3.2.19
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.6'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.6'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: Speed up development when using a Service Layer by easily creating service
98
+ classes and their attending test (spec) file.
99
+ email:
100
+ - imageaid@gmail.com
101
+ executables: []
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - ".gitignore"
106
+ - ".rspec"
107
+ - Gemfile
108
+ - LICENSE.txt
109
+ - README.md
110
+ - Rakefile
111
+ - lib/generators/rails_services/create/USAGE
112
+ - lib/generators/rails_services/create/create_generator.rb
113
+ - lib/generators/rails_services/create/templates/base_service.rb.erb
114
+ - lib/generators/rails_services/create/templates/base_service_spec.rb.erb
115
+ - lib/generators/rails_services/destroy/USAGE
116
+ - lib/generators/rails_services/destroy/destroy_generator.rb
117
+ - lib/rails_services.rb
118
+ - lib/rails_services/version.rb
119
+ - rails_services.gemspec
120
+ - spec/generators/rails_services/create/create_generator_spec.rb
121
+ - spec/generators/rails_services/destroy/destroy_generator_spec.rb
122
+ - spec/spec_helper.rb
123
+ homepage: https://github.com/imageaid/rails_service_generator
124
+ licenses:
125
+ - MIT
126
+ metadata: {}
127
+ post_install_message:
128
+ rdoc_options: []
129
+ require_paths:
130
+ - lib
131
+ required_ruby_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ required_rubygems_version: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - ">="
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
141
+ requirements: []
142
+ rubyforge_project:
143
+ rubygems_version: 2.2.2
144
+ signing_key:
145
+ specification_version: 4
146
+ summary: A Ruby gem that adds a rails generator for creating service classes.
147
+ test_files:
148
+ - spec/generators/rails_services/create/create_generator_spec.rb
149
+ - spec/generators/rails_services/destroy/destroy_generator_spec.rb
150
+ - spec/spec_helper.rb
151
+ has_rdoc: