eman 0.0.2

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: 5d47a00fe58b4d96d4dabeb13a427f912d554239
4
+ data.tar.gz: 08ffc135a0e4d33a20bc6bb836664323b8d56d97
5
+ SHA512:
6
+ metadata.gz: ee1b7507e854d0f04676742aaa9628e57be9bcc17d570cd39acfe795619fd40c1ff0190232f646a81a2375f8b5eb71740156b69790feb32503f906f6ea4f704f
7
+ data.tar.gz: 476c2d48c7966269715ff3032a6cc8c22fb5903c0e1dfe7e701556be2eab012d126eeaa1a5b240071fbe535b07ecd0e063afbc639567f2fe4e6b7e1b6cc3fca8
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --require spec_helper
3
+ --format documentation
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in eman.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Sung Won Cho
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,28 @@
1
+ # Eman
2
+
3
+ Easily name your controller, model, and service. Let Eman recommend you good names.
4
+
5
+ ## Why?
6
+
7
+ Well named files help your codebase to become more maintainable in the long run.
8
+
9
+ ## Installation
10
+
11
+ Install the gem:
12
+
13
+ $ gem install eman
14
+
15
+
16
+ ## Usage
17
+
18
+ Simply run the following commands as you see fit:
19
+
20
+ $ emac controller
21
+ $ emac model
22
+ $ emac service
23
+
24
+ ## Contributing
25
+
26
+ ### Recommendation system
27
+
28
+ Help us improve our recommendation system. Simply add new, relevant words in the dictionary YAML files.
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/bin/eman ADDED
@@ -0,0 +1,30 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "thor"
4
+ require "eman"
5
+
6
+ module Eman
7
+ class CLI < Thor
8
+
9
+ desc "controller", "name a controller"
10
+ def controller
11
+ generator = Eman::NameGenerator.new('Controller')
12
+ generator.run
13
+ end
14
+
15
+ desc "service", "name a service"
16
+ def service
17
+ generator = Eman::NameGenerator.new('Service')
18
+ generator.run
19
+ end
20
+
21
+ desc "model", "name a model"
22
+ def model
23
+ generator = Eman::NameGenerator.new('Model')
24
+ generator.run
25
+ end
26
+
27
+ end
28
+ end
29
+
30
+ Eman::CLI.start(ARGV)
data/eman.gemspec ADDED
@@ -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 'eman/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "eman"
8
+ spec.version = Eman::VERSION
9
+ spec.authors = ["Sung Won Cho"]
10
+ spec.email = ["mikeswcho@gmail.com"]
11
+ spec.summary = %q{Easily name your controller, model, and service.}
12
+ spec.description = %q{Easily name your controller, model, and service, with some further recommendations.}
13
+ spec.homepage = "https://github.com/sungwoncho/eman"
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_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "rspec", "~> 3.2.0"
24
+
25
+ spec.add_dependency "thor"
26
+ spec.add_dependency "activesupport"
27
+ end
@@ -0,0 +1,52 @@
1
+ require "active_support/inflector"
2
+
3
+ module Eman
4
+ class NameFormatter
5
+
6
+ attr_accessor :type, :resource, :verb
7
+
8
+ def initialize(resource, verb, type)
9
+ @type = type
10
+ @resource = is_controller_name? ? resource.pluralize : resource
11
+ @verb = verb
12
+ end
13
+
14
+ def camel_case!
15
+ if is_model_name?
16
+ "#{components_camelized}"
17
+ else
18
+ "#{components_camelized}#{type.capitalize}"
19
+ end
20
+ end
21
+
22
+ def snake_case!
23
+ if is_model_name?
24
+ "#{components_snakified}"
25
+ else
26
+ "#{components_snakified}_#{type.downcase}"
27
+ end
28
+ end
29
+
30
+ private
31
+
32
+ def components
33
+ [resource, verb].flat_map(&:split)
34
+ end
35
+
36
+ def components_camelized
37
+ components.collect(&:capitalize).join
38
+ end
39
+
40
+ def components_snakified
41
+ components.collect(&:downcase).join('_')
42
+ end
43
+
44
+ def is_controller_name?
45
+ type == 'Controller'
46
+ end
47
+
48
+ def is_model_name?
49
+ type == 'Model'
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,41 @@
1
+ module Eman
2
+ class NameGenerator
3
+
4
+ attr_accessor :resource, :verb, :name
5
+ attr_reader :type
6
+
7
+ def initialize(type)
8
+ @type = type
9
+ @resource = ''
10
+ @verb = ''
11
+ @name = ''
12
+ end
13
+
14
+ def run
15
+ ask_resource
16
+ ask_verb if type == 'Service'
17
+ generate_name
18
+ print_name
19
+ end
20
+
21
+ private
22
+
23
+ def ask_resource
24
+ puts "What is the resource that you are dealing with? (e.g. User, Session, Order, etc.)"
25
+ @resource = $stdin.gets.chomp
26
+ end
27
+
28
+ def ask_verb
29
+ puts "What is the primary action you are performing on '#{resource}'?"
30
+ @verb = $stdin.gets.chomp
31
+ end
32
+
33
+ def generate_name
34
+ @name = ::Eman::NameFormatter.new(@resource, @verb, @type).camel_case!
35
+ end
36
+
37
+ def print_name
38
+ puts "#{type} name : '#{name}'"
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,3 @@
1
+ module Eman
2
+ VERSION = "0.0.2"
3
+ end
data/lib/eman.rb ADDED
@@ -0,0 +1,8 @@
1
+ $:.unshift File.expand_path('../eman', __FILE__)
2
+
3
+ require "version"
4
+
5
+ module Eman
6
+ autoload :NameGenerator, 'name_generator'
7
+ autoload :NameFormatter, 'name_formatter'
8
+ end
data/spec/eman_spec.rb ADDED
@@ -0,0 +1,5 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe Eman do
4
+ it { should be_a(Module) }
5
+ end
@@ -0,0 +1,56 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe Eman::NameFormatter do
4
+
5
+ describe '#initialize' do
6
+ context 'when type is controller' do
7
+ it 'pluralizes the resource' do
8
+ formatter = Eman::NameFormatter.new('Alarm clock', 'Operating', 'Controller')
9
+ expect(formatter.resource).to eq 'Alarm clocks'
10
+ end
11
+ end
12
+
13
+ context 'when type is not controller' do
14
+ it 'does not pluralize the resource' do
15
+ formatter = Eman::NameFormatter.new('Alarm clock', 'Operating', 'Service')
16
+ expect(formatter.resource).to eq 'Alarm clock'
17
+ end
18
+ end
19
+ end
20
+
21
+ describe '#camel_case!' do
22
+ it 'outsputs a camel cased name' do
23
+ formatter = Eman::NameFormatter.new('cheese', 'grinding', 'Service')
24
+ outcome = formatter.camel_case!
25
+
26
+ expect(outcome).to eq 'CheeseGrindingService'
27
+ end
28
+
29
+ context 'when type is model' do
30
+ it 'does not append the type at the end' do
31
+ formatter = Eman::NameFormatter.new('Shopping', 'Cart', 'Model')
32
+ outcome = formatter.camel_case!
33
+
34
+ expect(outcome).to eq 'ShoppingCart'
35
+ end
36
+ end
37
+ end
38
+
39
+ describe '#snake_case!' do
40
+ it 'outputs a snake cased name' do
41
+ formatter = Eman::NameFormatter.new('guitar', 'smashing', 'Service')
42
+ outcome = formatter.snake_case!
43
+
44
+ expect(outcome).to eq 'guitar_smashing_service'
45
+ end
46
+
47
+ context 'when type is model' do
48
+ it 'does not append the type at the end' do
49
+ formatter = Eman::NameFormatter.new('Shopping', 'Cart', 'Model')
50
+ outcome = formatter.snake_case!
51
+
52
+ expect(outcome).to eq 'shopping_cart'
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,5 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe Eman::NameGenerator do
4
+
5
+ end
@@ -0,0 +1,94 @@
1
+ # Require all files under /lib
2
+ Dir[File.expand_path('../../lib/**/*.rb', __FILE__)].each { |f| require f }
3
+
4
+ # This file was generated by the `rspec --init` command. Conventionally, all
5
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
6
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
7
+ # this file to always be loaded, without a need to explicitly require it in any
8
+ # files.
9
+ #
10
+ # Given that it is always loaded, you are encouraged to keep this file as
11
+ # light-weight as possible. Requiring heavyweight dependencies from this file
12
+ # will add to the boot time of your test suite on EVERY test run, even for an
13
+ # individual file that may not need all of that loaded. Instead, consider making
14
+ # a separate helper file that requires the additional dependencies and performs
15
+ # the additional setup, and require it from the spec files that actually need
16
+ # it.
17
+ #
18
+ # The `.rspec` file also contains a few flags that are not defaults but that
19
+ # users commonly want.
20
+ #
21
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
22
+ RSpec.configure do |config|
23
+ # rspec-expectations config goes here. You can use an alternate
24
+ # assertion/expectation library such as wrong or the stdlib/minitest
25
+ # assertions if you prefer.
26
+ config.expect_with :rspec do |expectations|
27
+ # This option will default to `true` in RSpec 4. It makes the `description`
28
+ # and `failure_message` of custom matchers include text for helper methods
29
+ # defined using `chain`, e.g.:
30
+ # be_bigger_than(2).and_smaller_than(4).description
31
+ # # => "be bigger than 2 and smaller than 4"
32
+ # ...rather than:
33
+ # # => "be bigger than 2"
34
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
35
+ end
36
+
37
+ # rspec-mocks config goes here. You can use an alternate test double
38
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
39
+ config.mock_with :rspec do |mocks|
40
+ # Prevents you from mocking or stubbing a method that does not exist on
41
+ # a real object. This is generally recommended, and will default to
42
+ # `true` in RSpec 4.
43
+ mocks.verify_partial_doubles = true
44
+ end
45
+
46
+ # The settings below are suggested to provide a good initial experience
47
+ # with RSpec, but feel free to customize to your heart's content.
48
+ =begin
49
+ # These two settings work together to allow you to limit a spec run
50
+ # to individual examples or groups you care about by tagging them with
51
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
52
+ # get run.
53
+ config.filter_run :focus
54
+ config.run_all_when_everything_filtered = true
55
+
56
+ # Limits the available syntax to the non-monkey patched syntax that is
57
+ # recommended. For more details, see:
58
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
59
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
60
+ # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
61
+ config.disable_monkey_patching!
62
+
63
+ # This setting enables warnings. It's recommended, but in some cases may
64
+ # be too noisy due to issues in dependencies.
65
+ config.warnings = true
66
+
67
+ # Many RSpec users commonly either run the entire suite or an individual
68
+ # file, and it's useful to allow more verbose output when running an
69
+ # individual spec file.
70
+ if config.files_to_run.one?
71
+ # Use the documentation formatter for detailed output,
72
+ # unless a formatter has already been configured
73
+ # (e.g. via a command-line flag).
74
+ config.default_formatter = 'doc'
75
+ end
76
+
77
+ # Print the 10 slowest examples and example groups at the
78
+ # end of the spec run, to help surface which specs are running
79
+ # particularly slow.
80
+ config.profile_examples = 10
81
+
82
+ # Run specs in random order to surface order dependencies. If you find an
83
+ # order dependency and want to debug it, you can fix the order by providing
84
+ # the seed, which is printed after each run.
85
+ # --seed 1234
86
+ config.order = :random
87
+
88
+ # Seed global randomization in this process using the `--seed` CLI option.
89
+ # Setting this allows you to use `--seed` to deterministically reproduce
90
+ # test failures related to randomization by passing the same `--seed` value
91
+ # as the one that triggered the failure.
92
+ Kernel.srand config.seed
93
+ =end
94
+ end
metadata ADDED
@@ -0,0 +1,135 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: eman
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Sung Won Cho
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-03-21 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.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
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.2.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.2.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: thor
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
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: activesupport
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Easily name your controller, model, and service, with some further recommendations.
84
+ email:
85
+ - mikeswcho@gmail.com
86
+ executables:
87
+ - eman
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - ".rspec"
93
+ - Gemfile
94
+ - LICENSE.txt
95
+ - README.md
96
+ - Rakefile
97
+ - bin/eman
98
+ - eman.gemspec
99
+ - lib/eman.rb
100
+ - lib/eman/name_formatter.rb
101
+ - lib/eman/name_generator.rb
102
+ - lib/eman/version.rb
103
+ - spec/eman_spec.rb
104
+ - spec/name_formatter_spec.rb
105
+ - spec/name_generator_spec.rb
106
+ - spec/spec_helper.rb
107
+ homepage: https://github.com/sungwoncho/eman
108
+ licenses:
109
+ - MIT
110
+ metadata: {}
111
+ post_install_message:
112
+ rdoc_options: []
113
+ require_paths:
114
+ - lib
115
+ required_ruby_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ required_rubygems_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ requirements: []
126
+ rubyforge_project:
127
+ rubygems_version: 2.4.5
128
+ signing_key:
129
+ specification_version: 4
130
+ summary: Easily name your controller, model, and service.
131
+ test_files:
132
+ - spec/eman_spec.rb
133
+ - spec/name_formatter_spec.rb
134
+ - spec/name_generator_spec.rb
135
+ - spec/spec_helper.rb