d4c 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 0c1789a5f59487c598989f7f4e68c705a837ff9cd090cd34c88de8c83e4f1d60
4
+ data.tar.gz: 4c57c7649417d0f0a0905dd3a2554e59f265782a9fef4d7430c527f7fabf3824
5
+ SHA512:
6
+ metadata.gz: 581c5414eaa82616a81311d4318c5d369cc8a1efa227091a3102a4cb2e08a8a71333bd141ca7d499482de8d978bee25925e28670f2aa6d8b010fd49098237dbc
7
+ data.tar.gz: 665924f8d6d2e1ead11d00b82ff75b6f4f6f5e3706ffbca293b27a4365000134315caaeda4e5057fdbe73d3fa9280703791c66b6b6a38c7f117caeac7bbbb120
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2019 qwyng
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,74 @@
1
+ # D4C [![Build Status](https://travis-ci.org/QWYNG/D4C.svg?branch=master)](https://travis-ci.org/QWYNG/baby_face)
2
+ Easy add options to Rails console
3
+
4
+ ## Prerequisites
5
+ - Rails >= 5.1.0 Application
6
+ ## Installation
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'd4c'
11
+ ```
12
+
13
+ And then execute:
14
+ ```bash
15
+ $ bundle
16
+ ```
17
+
18
+ Or install it yourself as:
19
+ ```bash
20
+ $ gem install d4c
21
+ ```
22
+ ## Usage
23
+ Add option in _config/application.rb_
24
+
25
+ ```ruby
26
+ # frozen_string_literal: true
27
+
28
+ require_relative 'boot'
29
+
30
+ require 'rails/all'
31
+
32
+ Bundler.require(*Rails.groups)
33
+
34
+ D4C::Console.add_option 'hello' do
35
+ puts "hello"
36
+ end
37
+
38
+ module YourRailsApplication
39
+ class Application < Rails::Application
40
+
41
+ ```
42
+
43
+ ### Note
44
+ You need to put `D4C::Console.add_option` before YourRailsApplication module.
45
+ see also: https://guides.rubyonrails.org/configuring.html#running-code-before-rails
46
+
47
+ ### Option Description
48
+ you can set option description
49
+
50
+ ```ruby
51
+ D4C::Console.add_option 'hello', 'say hello!' do
52
+ puts "hello"
53
+ end
54
+ ```
55
+
56
+ ```bash
57
+ $rails c -h
58
+ Running via Spring preloader in process 13861
59
+ Usage:
60
+ bin/rails console [environment] [options]
61
+
62
+ Options:
63
+ -e, [--environment=ENVIRONMENT] # Specifies the environment to run this console under (test/development/production).
64
+ -s, [--sandbox], [--no-sandbox] # Rollback database modifications on exit.
65
+ [--hello], [--no-hello] # say hello
66
+
67
+ ```
68
+ ## Contributing
69
+ Bug reports and pull requests are welcome on GitHub at https://github.com/QWYNG/d4c. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.
70
+
71
+
72
+
73
+ ## License
74
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,27 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'D4c'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.md')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ require 'bundler/gem_tasks'
18
+
19
+ require 'rake/testtask'
20
+
21
+ Rake::TestTask.new(:test) do |t|
22
+ t.libs << 'test'
23
+ t.pattern = 'test/**/*_test.rb'
24
+ t.verbose = false
25
+ end
26
+
27
+ task default: :test
data/lib/d4c.rb ADDED
@@ -0,0 +1,5 @@
1
+ require 'd4c/console_option_set'
2
+ require 'd4c/rails'
3
+ require 'd4c/railtie'
4
+
5
+ D4C::Console = D4C::ConsoleOptionSet.new
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module D4C
4
+ class ConsoleOptionSet
5
+ attr_reader :options
6
+
7
+ Option = Struct.new(:name, :desc, :blk)
8
+
9
+ def initialize
10
+ @options = []
11
+ end
12
+
13
+ def add_option(name, desc = 'No description', &blk)
14
+ @options << Option.new(name, desc, blk)
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'prepended_options'
4
+
5
+ module D4C
6
+ module PrependClassOption
7
+ include PrependedOptions
8
+
9
+ def initialize(args = [], local_options = {}, config = {})
10
+ prepended_options.each do |option|
11
+ self.class.class_option option.name, type: :boolean, default: false, desc: option.desc
12
+ end
13
+
14
+ super
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'prepended_options'
4
+
5
+ module D4C
6
+ module PrependOptionAccessor
7
+ include PrependedOptions
8
+
9
+ def initialize(initial_variable_values = {}, &block)
10
+ prepended_options.each do |option|
11
+ self.class.attr_accessor option.name
12
+ end
13
+
14
+ super
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'prepended_options'
4
+
5
+ module D4C
6
+ module PrependOptionSetter
7
+ include PrependedOptions
8
+
9
+ def initialize(app, options = {})
10
+ prepended_options.each do |option|
11
+ app.send(option.name + '=', options[option.name.to_sym])
12
+ end
13
+
14
+ super
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module D4C
4
+ module PrependedOptions
5
+ def prepended_options
6
+ D4C::Console.options
7
+ end
8
+ end
9
+ end
data/lib/d4c/rails.rb ADDED
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails/command'
4
+ require 'rails/commands/console/console_command'
5
+ require 'rails/application'
6
+ require_relative 'prepend_option_setter'
7
+ require_relative 'prepend_option_accessor'
8
+ require_relative 'prepend_class_option'
9
+
10
+ module Rails
11
+ Application.prepend D4C::PrependOptionAccessor
12
+ Console.prepend D4C::PrependOptionSetter
13
+ Command::ConsoleCommand.prepend D4C::PrependClassOption
14
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module D4C
4
+ class Railtie < ::Rails::Railtie
5
+ console do |app|
6
+ include PrependedOptions
7
+
8
+ prepended_options.each do |option|
9
+ option.blk.call if app.send(option.name)
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,3 @@
1
+ module D4C
2
+ VERSION = '0.1.0'
3
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :d4c do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: d4c
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - qwyng
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-08-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 5.1.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 5.1.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: pry
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rubocop
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: sqlite3
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
+ description: DSL for add rails console option.
70
+ email:
71
+ - ikusawasi@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - MIT-LICENSE
77
+ - README.md
78
+ - Rakefile
79
+ - lib/d4c.rb
80
+ - lib/d4c/console_option_set.rb
81
+ - lib/d4c/prepend_class_option.rb
82
+ - lib/d4c/prepend_option_accessor.rb
83
+ - lib/d4c/prepend_option_setter.rb
84
+ - lib/d4c/prepended_options.rb
85
+ - lib/d4c/rails.rb
86
+ - lib/d4c/railtie.rb
87
+ - lib/d4c/version.rb
88
+ - lib/tasks/d4c_tasks.rake
89
+ homepage: https://github.com/QWYNG/d4c
90
+ licenses:
91
+ - MIT
92
+ metadata: {}
93
+ post_install_message:
94
+ rdoc_options: []
95
+ require_paths:
96
+ - lib
97
+ required_ruby_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ requirements: []
108
+ rubygems_version: 3.0.3
109
+ signing_key:
110
+ specification_version: 4
111
+ summary: easy to add rails console option.
112
+ test_files: []