gemmyrb 0.0.0 → 0.0.1

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
  SHA1:
3
- metadata.gz: 18532f58f02f659faa596f0ed22dd3f85acfa1a4
4
- data.tar.gz: 17ee68de85cf655f22bb5190e33a27378ecee904
3
+ metadata.gz: ee07c91962027fdbdf91efbc60abb03d4ffd502b
4
+ data.tar.gz: 7240a639bd4a4ee45d14e7bc43ed65974f54a192
5
5
  SHA512:
6
- metadata.gz: 32ef4734ff5168c54883208469f150927eb09053786e8dc6f5721f6d449061f509a60b0a1028eca628d973ef042339d4e55ee9be8d9c3edba1aea3ecf2e60d7c
7
- data.tar.gz: cee902db7fa77e8e555f6473bf4bd1191353206df35697d0ade31a5bcb0a13322db9335ebbb59a330810cb4aacc3c1ad3e04c0f035b5dabf99d06b0799360c85
6
+ metadata.gz: b8f6440c315b9c538ad06b178570d298f8f14e89b951221989cb122bcee97887f58a3ed05a80a2f76dcdd0af9f90492c3b7b13d6a94211c45f281d231e1ce030
7
+ data.tar.gz: 1356ede85fc8a5bd3fd6aeeedefb583d2c69be86511860997b5c16e7e663f1ecad0882af187b6904e93d9f3ad9a7cd986c31acc253c48ea5f0bfcc2154f1bd65
data/README.md CHANGED
@@ -1,18 +1,21 @@
1
1
  ### Gemmy gem
2
2
 
3
- This is a general purpose gem.
3
+ This is a general purpose gem which adds functionality to the ruby language
4
+ and defines some system tasks, such as generating a gem.
4
5
 
5
- I'm continually adding small core patches and utility classes.
6
+ It is on RubyGems. Because there is an existing gem named `gemmy`, the name passed to `gem install` is `gemmyrb`. But `require 'gemmy'` is still used.
6
7
 
7
- It is on RubyGems and can be installed with `gem install gemmyrb`
8
+ RubyGems hosts the YARD documentation at [http://www.rubydoc.info/gems/gemmyrb](http://www.rubydoc.info/gems/gemmyrb), but it's only updated when I push
9
+ a new gem version. So the version here on Github's master branch might contain
10
+ undocumented functionality. I'll try to keep the RubyGems version up-to-date though.
8
11
 
9
- **note**
12
+ YARD is not the best for a birds-eye overview. For that, see the following
13
+ documents:
10
14
 
11
- because there is an existing gem named `gemmy`, the name passed
12
- to `gem install` is `gemmyrb`. But `require 'gemmy'` is still used.
13
-
14
- For more information, see the following documents:
15
-
16
- - [examples/01_using_as_refinement.rb](.examples/01_using_as_refinement.rb)
17
- - [examples/02_using_globally.rb](.examples/02_using_globally.rb)
18
- - [examples/03_full_api.rb](.examples/03_full_api.rb)
15
+ - _Loading the gem's code in different scopes_
16
+ - [examples/01_using_as_refinement.rb](./examples/01_using_as_refinement.rb)
17
+ - [examples/02_using_globally.rb](./examples/02_using_globally.rb)
18
+ - _List of methods intended for general Ruby use_
19
+ - [examples/03_ruby_extensions_list.rb](./examples/03_ruby_extensions_list.rb)
20
+ - _Shell commands and other one-off processes_
21
+ - [examples/04_shell_commands.rb](./04_shell_commands.rb)
@@ -1,6 +1,7 @@
1
1
  # Mimics the Cucumber API:
2
- # {DynamicSteps#step} runs a step
3
- # {DynamicSteps#define_step} defines a step
2
+ #
3
+ # {#step} runs a step
4
+ # {#define_step} defines a step
4
5
  #
5
6
  # The usage is the same as Cucumber:
6
7
  #
@@ -12,7 +13,7 @@
12
13
  # => 'hellohello'
13
14
  #
14
15
  # Like Cucumber, it will raise an error if there is > 1 matching step
15
- # {DynamicSteps::AmbiguousMatchError} can be rescued if desired.
16
+ # AmbiguousMatchError can be rescued if desired.
16
17
  #
17
18
  # It also raises an error if no matcher was found
18
19
  #
@@ -20,10 +21,6 @@ module Gemmy::Components::DynamicSteps
20
21
 
21
22
  Gemmy::Patches.refinements.each { |r| using r }
22
23
 
23
- # A hash mapping regex to proc
24
- #
25
- attr_reader :steps
26
-
27
24
  # Error raised when a string matches multiple step regexes.
28
25
  # It's frequently accidental to come into this situation,
29
26
  # and having this check prevents surprise errors.
@@ -75,10 +72,11 @@ module Gemmy::Components::DynamicSteps
75
72
  end
76
73
  end
77
74
 
78
- # Searches the keys in @steps for a regex the matches the string.
79
- # If one is found, it adds the regex as a key in the results hash.
80
- # The value is a hash with two keys: :matches (an array) and :proc
81
- #
75
+ # Searches the keys in @steps for regexes that match the string.
76
+ # @param string [String]
77
+ # @return [Hash] where keys are regexes and vals are hashes with signature:
78
+ # matches: [Array<String>] the String#match results
79
+ # proc: [Proc] the block mapped to the regex
82
80
  def find_matching_steps(string)
83
81
  matching_steps = steps.reduce({}) do |matching_steps, (regex, proc)|
84
82
  match_results = string.match(regex).to_a.tap &:shift
@@ -1,4 +1,4 @@
1
- # Global patches. Could be applied to Object or Kernel
1
+ # Array patches
2
2
  #
3
3
  module Gemmy::Patches::ArrayPatch
4
4
  # checks if any of the results of an array do not respond truthily
@@ -35,7 +35,7 @@ module Gemmy::Patches::ObjectPatch
35
35
  # @param text [String] text to write
36
36
  #
37
37
  def write(file:, text:)
38
- File.open(file, 'w', &:write.with(text))
38
+ File.open(file, 'w') { |f| f.write text }
39
39
  end
40
40
 
41
41
  # if args[0] (object) is blank, raises args[1] (message)
data/lib/gemmy/patches.rb CHANGED
@@ -1,13 +1,23 @@
1
1
  # Gemmy provides patches for a few of the core classes.
2
2
  #
3
- # For example:
4
- # Gemmy::Patches.load(only: [:string])
5
- # Gemmy::Patches.load(except: [:symbol, :global])
3
+ # See {Gemmy#load_globally} for how to load these on the root namespace
4
+ # For a refinements-based approach, use this in a class/module definition:
5
+ #
6
+ # Gemmy::Patches.refinements.each { |klass| using klass }
7
+ #
8
+ # Note that there are nuances for how refinements are used. You can't refer to
9
+ # the patches using define_method, for example.
10
+ #
11
+ # See examples/01_using_as_refinement.rb for more info
6
12
  #
7
13
  module Gemmy::Patches
8
14
 
9
- def self.refinements
10
- core_patches.values
15
+ def self.refinements(only: nil, except: nil)
16
+ core_patches.select do |core_klass, patch_klass|
17
+ return false if only && !only.include?(core_klass)
18
+ return false if except && except.include?(core_klass)
19
+ true
20
+ end.values
11
21
  end
12
22
 
13
23
  def self.core_patches
@@ -19,7 +29,7 @@ module Gemmy::Patches
19
29
  Method: Gemmy::Patches::MethodPatch,
20
30
  Hash: Gemmy::Patches::HashPatch,
21
31
  Thread: Gemmy::Patches::ThreadPatch,
22
- }
32
+ }.with_indifferent_access
23
33
  end
24
34
 
25
35
  end
@@ -1,6 +1,6 @@
1
1
  # A task to create skeleton structure for a ruby gem
2
2
  #
3
- # Only one method is intended for public use, {Tasks::MakeGem#run}.
3
+ # Only one method is intended for public use, {run}.
4
4
  #
5
5
  # It takes one argument - the name of the ruby gem.
6
6
  #
@@ -10,6 +10,9 @@
10
10
  #
11
11
  # ├── <name>.gemspec
12
12
  # ├── Gemfile
13
+ # ├── reinstall
14
+ # ├── bin
15
+ # └── <name>
13
16
  # └── lib
14
17
  # ├── <name>.rb
15
18
  # └── version.rb
@@ -42,6 +45,8 @@ class Gemmy::Tasks::MakeGem
42
45
  create_gemspec_file
43
46
  create_gemfile
44
47
  create_reinstall_file
48
+ create_executable
49
+ puts "directory #{name} has been created".yellow
45
50
  end
46
51
 
47
52
  attr_reader :name, :root_dir, :lib, :version_file, :main_file, :summary,
@@ -50,32 +55,17 @@ class Gemmy::Tasks::MakeGem
50
55
 
51
56
  private
52
57
 
53
- # A reinstall file is very helpful for development
54
- def create_reinstall_file
55
- file_txt = <<-TXT.unindent
56
- #!/usr/bin/env ruby
57
- puts `gem uninstall -x #{name}`
58
- puts `gem build #{name}.gemspec`
59
- Dir.glob("./*.gem").each { |path| puts `gem install #{path}` }
60
- TXT
61
- file_path = "#{root_dir}/reinstall"
62
- File.open(file_path, 'w') do |file|
63
- file.write file_txt
64
- end
65
- `chmod a+x #{file_path}`
66
- end
67
-
68
58
  # prints usage instructions unless the gem name was specified
69
59
  #
70
60
  def usage_io
71
- usage = <<-TXT.unindent
72
- \nUsage: make_gem <name>
73
- TXT
74
- raise usage if @name.blank?
61
+ if @name.blank?
62
+ puts "\nUsage: make_gem <name>"
63
+ exit
64
+ end
75
65
  self
76
66
  end
77
67
 
78
- # creates a root directory for the gem
68
+ # Creates a root directory for the gem
79
69
  #
80
70
  def create_root_dir
81
71
  @root_dir = name
@@ -185,5 +175,45 @@ class Gemmy::Tasks::MakeGem
185
175
  self
186
176
  end
187
177
 
178
+ # A reinstall file is very helpful for development
179
+ def create_reinstall_file
180
+ file_txt = <<-TXT.unindent
181
+ #!/usr/bin/env ruby
182
+ Dir.glob("./*.gem").each { |path| `rm \#{path}` }
183
+ puts `gem uninstall -x #{name}`
184
+ puts `gem build #{name}.gemspec`
185
+ Dir.glob("./*.gem").each { |path| puts `gem install -f \#{path}` }
186
+ TXT
187
+ file_path = "#{root_dir}/reinstall"
188
+ File.open(file_path, 'w') do |file|
189
+ file.write file_txt
190
+ end
191
+ `chmod a+x #{file_path}`
192
+ puts "wrote reinstall file".green
193
+ end
194
+
195
+ # Creates an empty gem executable which requires the gem.
196
+ # This makes it easy to call functions from the ruby codebase.
197
+ # The Thor CLI library is used, see whatisthor.com
198
+ def create_executable
199
+ file_txt = <<-TXT.unindent
200
+ #!/usr/bin/env ruby
201
+ require '#{name}'
202
+ class #{class_name}::CLI < Thor
203
+ desc "test", "run tests"
204
+ def test
205
+ puts "No tests have been wrritten"
206
+ exit
207
+ end
208
+ end
209
+ #{class_name}::CLI.start ARGV
210
+ TXT
211
+ `mkdir #{root_dir}/bin`
212
+ file_path = "#{root_dir}/bin/#{name}"
213
+ write(file: "#{file_path}", text: file_txt)
214
+ `chmod a+x #{file_path}`
215
+ puts "wrote executable".green
216
+ end
217
+
188
218
  end
189
219
 
data/lib/gemmy/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  class Gemmy
2
- VERSION = '0.0.0'
2
+ VERSION = '0.0.1'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gemmyrb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - max pleaner
@@ -137,5 +137,6 @@ rubyforge_project:
137
137
  rubygems_version: 2.5.1
138
138
  signing_key:
139
139
  specification_version: 4
140
- summary: general utils
140
+ summary: Some general ruby language utils, including a gem generator. See http://github.com/maxpleaner/gemmy
141
+ for more detail
141
142
  test_files: []