pry-singular 0.1.7 → 0.1.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: acd994b7048150ee8e0f2fd07b5fb57e82c30c704f19be6b46224231df9b4741
4
- data.tar.gz: 39a5cd0137a785cd102ecef82338c0522d41e142f76fb0629faf893b058e18e7
3
+ metadata.gz: 1e29520ac622fa873c590c83aff04d4771ecf4af5678ff56953dadf637410986
4
+ data.tar.gz: b55d7c89167c2c3923df7cbf8bacb9a157db707f06a4ab1c35834cadcfb1d3f7
5
5
  SHA512:
6
- metadata.gz: de49b859e64d4d87303c9cb29da1e0746dbcda1d5f807107adcddb882602f53d474b88135f9e16448b5e4da0d505de8216d49825550b61dc3f05f93dd599c41c
7
- data.tar.gz: 389a3ef406247ae2b4ba97d76b3a6a8efc985e583020281a4b64187201b6379fbad29e20266bfe7b936edc3c54956045bf322e5c862ed138a8365eb0802be281
6
+ metadata.gz: 382795b995205e1eba5545c581a11dd8b91cbf830fac8a12f6b61f4602b26fd35dbdd9e934b88a9370d3d01ef87d769dbbdec054ae3e42a4d1410e2563c6ad5e
7
+ data.tar.gz: e068ae185bc88b796a202d884fd4122fb9978b835e16d38961fcbe497897d3c24879b61d68c4a28cc704202d034f20b81f2b3a80baeda08de91d714a074bbda1
@@ -0,0 +1,6 @@
1
+ parallel: true
2
+ format: progress
3
+ ignore:
4
+ - 'test/*':
5
+ - Style/EmptyMethod
6
+ - Style/SingleLineMethods
@@ -4,4 +4,7 @@ language: ruby
4
4
  cache: bundler
5
5
  rvm:
6
6
  - 2.6.3
7
- before_install: gem install bundler -v 1.17.2
7
+ before_install:
8
+ - gem install bundler -v 1.17.2
9
+ - gem install standard
10
+ script: bundle exec standardrb
data/Gemfile CHANGED
@@ -1,6 +1,6 @@
1
1
  source "https://rubygems.org"
2
2
 
3
- git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
3
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
4
 
5
5
  # Specify your gem's dependencies in pry-pry-singular.gemspec
6
6
  gemspec
data/README.md CHANGED
@@ -21,7 +21,7 @@ Or install it yourself as:
21
21
  Set `.pryrc` as below
22
22
 
23
23
  ```ruby
24
- PrySingular.set_class FooJob, FactoryBot
24
+ PrySingular.make_commands FooJob, FactoryBot
25
25
  ```
26
26
 
27
27
  then you can use singular method of set class as pry command
@@ -37,13 +37,13 @@ Pry-Singular add only `singleton_methods(true)` for do not create core Ruby meth
37
37
  If you have a method you want to specify write as below
38
38
 
39
39
  ```ruby
40
- PrySingular.set_class FactoryBot, only: [:build, :attributes_for]
40
+ PrySingular.make_commands FactoryBot, only: [:build, :attributes_for]
41
41
  ```
42
42
 
43
43
  Also, If you have a method that you don't want to command
44
44
 
45
45
  ```ruby
46
- PrySingular.set_class FactoryBot, except: [:create]
46
+ PrySingular.make_commands FactoryBot, except: :create
47
47
  ```
48
48
 
49
49
 
data/Rakefile CHANGED
@@ -7,4 +7,4 @@ Rake::TestTask.new(:test) do |t|
7
7
  t.test_files = FileList["test/**/*_test.rb"]
8
8
  end
9
9
 
10
- task :default => :test
10
+ task default: :test
@@ -1,50 +1,50 @@
1
- require 'pry-singular/version'
2
- require 'pry-singular/extract_pry_singular_options'
3
- require 'pry-singular/parse_readline'
4
- require 'pry'
1
+ require "pry-singular/version"
2
+ require "pry-singular/slop"
3
+ require "pry-singular/option"
4
+ require "pry"
5
5
 
6
6
  module PrySingular
7
7
  class << self
8
- def set_class(*klasses)
9
- options = klasses.extract_pry_singular_options!
10
- normalize_pry_singular_options!(options)
8
+ def make_commands(*klasses, **options)
9
+ options = Options.new(options)
11
10
  klasses.each do |klass|
12
- import_class_command(klass, options)
11
+ create_singular_method_commands(klass, options)
13
12
  end
14
13
  end
15
14
 
16
15
  private
17
16
 
18
- def normalize_pry_singular_options!(options)
19
- options[:only] = Array(options[:only])
20
- options[:except] = Array(options[:except])
21
- end
17
+ def create_singular_method_commands(klass, options)
18
+ filtered_singular_methods = filter_methods_by_option(klass.singleton_methods, options)
22
19
 
23
- def import_class_command(klass, options)
24
- singular_methods = adapt_options_singleton_methods(klass, options)
25
- set_pry_command do
26
- singular_methods.each do |klass_method|
27
- command "#{klass_method}", "#{klass}.#{klass_method}" do
28
- extend PrySingular::Slop
29
- klass.class_eval <<-EOS
30
- #{parse_singular_method_command(Readline::HISTORY.to_a.last)}
31
- EOS
32
- end
33
- end
20
+ filtered_singular_methods.each do |singular_method|
21
+ singular_method_command(singular_method, klass)
34
22
  end
35
23
  end
36
24
 
37
- def set_pry_command(&block)
38
- commands = Pry::CommandSet.new &block
39
- Pry.config.commands.import(commands)
25
+ def filter_methods_by_option(methods, options)
26
+ if options.only.any?
27
+ options.remove_methods_other_than_only(methods)
28
+ else
29
+ options.remove_except_methods(methods)
30
+ end
40
31
  end
41
32
 
42
- def adapt_options_singleton_methods(klass, options)
43
- if options[:only].any?
44
- return options[:only].select { |method_name| klass.respond_to?(method_name) }
33
+ def singular_method_command(singular_method, klass)
34
+ import_pry_command do
35
+ command singular_method.to_s, "#{klass}.#{singular_method}" do
36
+ last_cui_command = Readline::HISTORY.to_a.last
37
+
38
+ klass.class_eval <<~EOS, __FILE__, __LINE__ + 1
39
+ #{PrySingular::Slop.parse_singular_method_command(last_cui_command)}
40
+ EOS
41
+ end
45
42
  end
43
+ end
46
44
 
47
- klass.singleton_methods - options[:except]
45
+ def import_pry_command(&block)
46
+ commands = Pry::CommandSet.new(&block)
47
+ Pry.config.commands.import(commands)
48
48
  end
49
49
  end
50
50
  end
@@ -0,0 +1,15 @@
1
+ module PrySingular
2
+ Options = Struct.new(:only, :except) {
3
+ def initialize(**options)
4
+ super(Array(options[:only]), Array(options[:except]))
5
+ end
6
+
7
+ def remove_methods_other_than_only(methods)
8
+ methods & only
9
+ end
10
+
11
+ def remove_except_methods(methods)
12
+ methods - except
13
+ end
14
+ }
15
+ end
@@ -0,0 +1,12 @@
1
+ require "pry"
2
+
3
+ module PrySingular
4
+ module Slop
5
+ def parse_singular_method_command(command)
6
+ method, args = command.split(" ", 2)
7
+ "#{method} #{args.delete(" ")}"
8
+ end
9
+
10
+ module_function :parse_singular_method_command
11
+ end
12
+ end
@@ -1,3 +1,3 @@
1
1
  module PrySingular
2
- VERSION = "0.1.7"
2
+ VERSION = "0.1.8"
3
3
  end
@@ -1,4 +1,3 @@
1
-
2
1
  lib = File.expand_path("../lib", __FILE__)
3
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
3
  require "pry-singular/version"
@@ -9,13 +8,13 @@ Gem::Specification.new do |spec|
9
8
  spec.authors = ["qwyng"]
10
9
  spec.email = ["ikusawasi@gmail.com"]
11
10
 
12
- spec.summary = %q{setting class methods as pry command}
11
+ spec.summary = "setting class methods as pry command"
13
12
  spec.homepage = "https://github.com/QWYNG/pry-singular"
14
13
  spec.license = "MIT"
15
14
 
16
15
  # Specify which files should be added to the gem when it is released.
17
16
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
18
- spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
17
+ spec.files = Dir.chdir(File.expand_path("..", __FILE__)) do
19
18
  `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
20
19
  end
21
20
  spec.bindir = "exe"
@@ -26,4 +25,5 @@ Gem::Specification.new do |spec|
26
25
  spec.add_development_dependency "bundler", "~> 1.17"
27
26
  spec.add_development_dependency "rake", "~> 10.0"
28
27
  spec.add_development_dependency "minitest", "~> 5.0"
28
+ spec.add_development_dependency "standard"
29
29
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pry-singular
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - qwyng
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-07-15 00:00:00.000000000 Z
11
+ date: 2019-07-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pry
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '5.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: standard
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'
69
83
  description:
70
84
  email:
71
85
  - ikusawasi@gmail.com
@@ -74,6 +88,7 @@ extensions: []
74
88
  extra_rdoc_files: []
75
89
  files:
76
90
  - ".gitignore"
91
+ - ".standard.yml"
77
92
  - ".travis.yml"
78
93
  - CODE_OF_CONDUCT.md
79
94
  - Gemfile
@@ -83,8 +98,8 @@ files:
83
98
  - bin/console
84
99
  - bin/setup
85
100
  - lib/pry-singular.rb
86
- - lib/pry-singular/extract_pry_singular_options.rb
87
- - lib/pry-singular/parse_readline.rb
101
+ - lib/pry-singular/option.rb
102
+ - lib/pry-singular/slop.rb
88
103
  - lib/pry-singular/version.rb
89
104
  - pry-singular.gemspec
90
105
  homepage: https://github.com/QWYNG/pry-singular
@@ -1,9 +0,0 @@
1
- class Array
2
- def extract_pry_singular_options!
3
- if last.is_a?(Hash)
4
- pop
5
- else
6
- {}
7
- end
8
- end
9
- end
@@ -1,10 +0,0 @@
1
- require 'pry'
2
-
3
- module PrySingular
4
- module Slop
5
- def parse_singular_method_command(items)
6
- method, args = items.split(" ", 2)
7
- method + ' ' + args.gsub(' ', '')
8
- end
9
- end
10
- end