faker-shorthand 0.1.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
+ SHA256:
3
+ metadata.gz: a0a7fe67d0f0cfde1e35d173e9bcbb7a43d6b72277ea0de074c58cecc09f8946
4
+ data.tar.gz: a6bad53bd0cbacfa1d24488c94e039beabafde55a3ef4e53dc4ca8f34906a5ec
5
+ SHA512:
6
+ metadata.gz: b03c877c798f14aeab2accce8b3063e6c2e33160e4c35c76cf0048b2de04530952fde27e4643fdb2bd65577de1c21d83a46a5633516666502571d61874892b34
7
+ data.tar.gz: dd4d149f3d4e0573388d60a9180ca7e5d03a038020a170f0d13feaf95aa47ec6778e71bf76d96bacd74b93c260bc2300c595ce298fa418f5ef51b72d9aa7d7a2
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at acuppy@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [https://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: https://contributor-covenant.org
74
+ [version]: https://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in faker_shorthand.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
7
+ gem "minitest", "~> 5.0"
8
+ gem 'guard' # NOTE: this is necessary in newer versions
9
+ gem 'guard-minitest'
10
+ gem "pry"
data/Gemfile.lock ADDED
@@ -0,0 +1,63 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ faker_shorthand (0.1.0)
5
+ faker
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ coderay (1.1.3)
11
+ concurrent-ruby (1.2.2)
12
+ faker (3.1.1)
13
+ i18n (>= 1.8.11, < 2)
14
+ ffi (1.15.5)
15
+ formatador (1.1.0)
16
+ guard (2.18.0)
17
+ formatador (>= 0.2.4)
18
+ listen (>= 2.7, < 4.0)
19
+ lumberjack (>= 1.0.12, < 2.0)
20
+ nenv (~> 0.1)
21
+ notiffany (~> 0.0)
22
+ pry (>= 0.13.0)
23
+ shellany (~> 0.0)
24
+ thor (>= 0.18.1)
25
+ guard-compat (1.2.1)
26
+ guard-minitest (2.4.6)
27
+ guard-compat (~> 1.2)
28
+ minitest (>= 3.0)
29
+ i18n (1.12.0)
30
+ concurrent-ruby (~> 1.0)
31
+ listen (3.8.0)
32
+ rb-fsevent (~> 0.10, >= 0.10.3)
33
+ rb-inotify (~> 0.9, >= 0.9.10)
34
+ lumberjack (1.2.8)
35
+ method_source (1.0.0)
36
+ minitest (5.18.0)
37
+ nenv (0.3.0)
38
+ notiffany (0.1.3)
39
+ nenv (~> 0.1)
40
+ shellany (~> 0.0)
41
+ pry (0.14.2)
42
+ coderay (~> 1.1)
43
+ method_source (~> 1.0)
44
+ rake (12.3.3)
45
+ rb-fsevent (0.11.2)
46
+ rb-inotify (0.10.1)
47
+ ffi (~> 1.0)
48
+ shellany (0.0.1)
49
+ thor (1.2.1)
50
+
51
+ PLATFORMS
52
+ ruby
53
+
54
+ DEPENDENCIES
55
+ faker_shorthand!
56
+ guard
57
+ guard-minitest
58
+ minitest (~> 5.0)
59
+ pry
60
+ rake (~> 12.0)
61
+
62
+ BUNDLED WITH
63
+ 2.1.4
data/Guardfile ADDED
@@ -0,0 +1,23 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ ## Uncomment and set this to only include directories you want to watch
5
+ # directories %w(app lib config test spec features) \
6
+ # .select{|d| Dir.exist?(d) ? d : UI.warning("Directory #{d} does not exist")}
7
+
8
+ ## Note: if you are using the `directories` clause above and you are not
9
+ ## watching the project directory ('.'), then you will want to move
10
+ ## the Guardfile to a watched dir and symlink it back, e.g.
11
+ #
12
+ # $ mkdir config
13
+ # $ mv Guardfile config/
14
+ # $ ln -s config/Guardfile .
15
+ #
16
+ # and, you'll have to watch "config/Guardfile" instead of "Guardfile"
17
+
18
+ guard :minitest do
19
+ # with Minitest::Unit
20
+ watch(%r{^test/(.*)\/?(.*)_test\.rb$})
21
+ watch(%r{^lib/(.*/)?([^/]+)\.rb$})
22
+ watch(%r{^test/test_helper\.rb$}) { 'test' }
23
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023 Adam Cuppy
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,77 @@
1
+ # Faker::Shorthand (for Ruby)
2
+
3
+ :tired_face: Tied of writing `Faker::Name.name` over and over again?! Me too. But, you're in luck :smile:, there's a app (gem) for that! With `Faker::Shorthand`, you too can save your shift-key and milliseconds of exta keyboarding...
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'faker-shorthand'
11
+ ```
12
+
13
+ Then execute:
14
+
15
+ $ bundle install
16
+
17
+ And last, but not least, add to your preferred test_helper (along with Faker itself):
18
+
19
+ ```ruby
20
+ require 'faker/shorthand'
21
+ ```
22
+
23
+ ## Usage
24
+
25
+ Instead of `Faker::ChuckNorris.fact` simply write `f.chuck_norris.fact` and :boom: you get everything you've ever wanted (...from that Faker module). The mapping is quite simple.
26
+
27
+ We have support for single and multiword modules and methods!
28
+
29
+ In case you're worried, we won't lose those all so valuable keyword and method arguments. Just pass those along, and _we will too_.
30
+
31
+ Let our Faker methods be your Faker methods.
32
+
33
+ ## :question: Never Asked Questions:
34
+
35
+ - "WHAT IF I HATE SHORTHAND?!" No problem. You can use your trusty shift-key to write out all of those capitalized module/class declarations.
36
+
37
+ - "Hmmm, what about my custom Faker extension?" No problem. It's just shorthand. We don't override any modules. If your version of Faker has it, so do we!
38
+
39
+ - "I use FactoryBot, can I integrate this glorious shorthand?" Of course - do you think we'd forget about you! No silly human. With one line of code in your `test_helper` of choice and you have shorthand everywhere!!
40
+
41
+ ## FactoryBot integration
42
+
43
+ Include the following line in your preferred test_helper _after_ requiring FactoryBot:
44
+
45
+ ```ruby
46
+ class FactoryBot::SyntaxRunner
47
+ include Faker::Shorthand::Methods
48
+ end
49
+ ```
50
+
51
+ ## Coming soon (launching 2023/4/5-ish)
52
+
53
+ ### Aliases
54
+ Shorten the shorthand with a single line of configuration, `f.name.name` will become `f.name`, and `f.name.first_name` to become `f.name.first`.
55
+
56
+ ### Compositions
57
+ Who loves combining strings anyways?! Not us at the Institute of Faker::Shorthand. With a touch of configuration, we can make all of that go away. Ask for `f.name.first.and.last` and you've made `"#{Faker::Name.first_name} #{Faker::Name.last_name}` and thing of the past. (This may be a horrible idea. It's not entirely clear at this point.)
58
+
59
+
60
+ ## Development
61
+
62
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
63
+
64
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
65
+
66
+ ## Contributing
67
+
68
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/faker_shorthand. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/faker_shorthand/blob/master/CODE_OF_CONDUCT.md).
69
+
70
+
71
+ ## License
72
+
73
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
74
+
75
+ ## Code of Conduct
76
+
77
+ Everyone interacting in the FakerShorthand project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/faker_shorthand/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
+ end
9
+
10
+ task :default => :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "faker_shorthand"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,28 @@
1
+ require_relative 'lib/faker/shorthand'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "faker-shorthand"
5
+ spec.version = Faker::Shorthand::VERSION
6
+ spec.authors = ["Adam Cuppy"]
7
+ spec.email = ["acuppy@hey.com"]
8
+
9
+ spec.summary = %q{Shorthand for the Faker generator syntax}
10
+ spec.description = %q{Shorthand for the Faker generator syntax}
11
+ spec.homepage = "https://github.com/acuppy/faker_shorthand"
12
+ spec.license = "MIT"
13
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
14
+
15
+ spec.metadata["homepage_uri"] = spec.homepage
16
+ spec.metadata["source_code_uri"] = "https://github.com/acuppy/faker_shorthand"
17
+ spec.metadata["changelog_uri"] = "https://github.com/acuppy/faker_shorthand"
18
+
19
+ # Specify which files should be added to the gem when it is released.
20
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
21
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
22
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
23
+ end
24
+ spec.bindir = "exe"
25
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
26
+ spec.require_paths = ["lib"]
27
+ spec.add_dependency 'faker'
28
+ end
@@ -0,0 +1,55 @@
1
+ module Faker
2
+ module Shorthand
3
+ class Matcher
4
+ def initialize
5
+ @klass = nil
6
+ @method = nil
7
+ end
8
+
9
+ def method_missing(method, **args, &block)
10
+ unless @klass
11
+ catch_module_errors { define_faker_class(method) }
12
+ self
13
+ else
14
+ catch_method_errors { send_faker_method(method, **args, &block) }
15
+ end
16
+ end
17
+
18
+ private
19
+
20
+ def assert_method?(method)
21
+ @klass.methods(false).include? method.to_sym
22
+ end
23
+
24
+ def classify(klass)
25
+ klass.to_s.split('_').collect(&:capitalize).join
26
+ end
27
+
28
+ def catch_module_errors(&block)
29
+ block.call
30
+ rescue NameError, TypeError => e
31
+ raise MatcherModuleError.new(e)
32
+ end
33
+
34
+ def catch_method_errors(&block)
35
+ block.call
36
+ rescue ArgumentError => e
37
+ raise MatcherArgumentError.new(@klass_name, @method, e)
38
+ end
39
+
40
+ def define_faker_class(klass_name)
41
+ @klass_name = classify(klass_name)
42
+ @klass ||= Faker.const_get(@klass_name)
43
+ end
44
+
45
+ def send_faker_method(method, **args, &block)
46
+ unless assert_method?(method)
47
+ raise MatcherMethodError.new(@klass_name, method)
48
+ end
49
+
50
+ @method = method
51
+ @klass.public_send(@method, **args, &block)
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,11 @@
1
+ module Faker
2
+ module Shorthand
3
+ module Methods
4
+ def fake
5
+ Faker::Shorthand::Matcher.new
6
+ end
7
+
8
+ alias_method :f, :fake
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,26 @@
1
+ require_relative "shorthand/matcher"
2
+ require_relative "shorthand/methods"
3
+
4
+ module Faker
5
+ module Shorthand
6
+ VERSION = "0.1.0"
7
+
8
+ class MatcherModuleError < StandardError
9
+ def initialize(module_name)
10
+ super "No Faker module matches Faker::#{module_name}"
11
+ end
12
+ end
13
+
14
+ class MatcherMethodError < NoMethodError
15
+ def initialize(module_name, method_name)
16
+ super "No generator method matches Faker::#{module_name}.#{method_name}"
17
+ end
18
+ end
19
+
20
+ class MatcherArgumentError < ArgumentError
21
+ def initialize(module_name, method_name, e)
22
+ super "Faker::#{module_name}.#{method_name}: #{e}"
23
+ end
24
+ end
25
+ end
26
+ end
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: faker-shorthand
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Adam Cuppy
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2023-03-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faker
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: Shorthand for the Faker generator syntax
28
+ email:
29
+ - acuppy@hey.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".gitignore"
35
+ - CODE_OF_CONDUCT.md
36
+ - Gemfile
37
+ - Gemfile.lock
38
+ - Guardfile
39
+ - LICENSE.txt
40
+ - README.md
41
+ - Rakefile
42
+ - bin/console
43
+ - bin/setup
44
+ - faker_shorthand.gemspec
45
+ - lib/faker/shorthand.rb
46
+ - lib/faker/shorthand/matcher.rb
47
+ - lib/faker/shorthand/methods.rb
48
+ homepage: https://github.com/acuppy/faker_shorthand
49
+ licenses:
50
+ - MIT
51
+ metadata:
52
+ homepage_uri: https://github.com/acuppy/faker_shorthand
53
+ source_code_uri: https://github.com/acuppy/faker_shorthand
54
+ changelog_uri: https://github.com/acuppy/faker_shorthand
55
+ post_install_message:
56
+ rdoc_options: []
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: 2.3.0
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ requirements: []
70
+ rubygems_version: 3.1.2
71
+ signing_key:
72
+ specification_version: 4
73
+ summary: Shorthand for the Faker generator syntax
74
+ test_files: []