Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/the-rubies-way/fake_picture

Simple way to generate fake pictures by included in gem pictures for your blog, user and other type of seeds for dev env or even RSpec tests
https://github.com/the-rubies-way/fake_picture

awesome easy easy-to-use fake fake-images fake-pictures faker faker-generator faker-image gem image picture rails random rspec ruby ruby-on-rails rubyonrails

Last synced: 6 days ago
JSON representation

Simple way to generate fake pictures by included in gem pictures for your blog, user and other type of seeds for dev env or even RSpec tests

Awesome Lists containing this project

README

        

[![Actions Status](https://github.com/loqimean/fake_picture/actions/workflows/CI.yml/badge.svg)](https://github.com/loqimean/fake_picture/actions)
[![Listed on OpenSource-Heroes.com](https://opensource-heroes.com/badge-v1.svg)](https://opensource-heroes.com/r/loqimean/fake_picture)

# FakePicture

Welcome to my new gem! This is a gem for simple seeding, testing and etc by uploading fake pictures. Now you don't need to create too many folders with pictures, because you can use this gem which can give you the path to a random picture of a selected category or file if you need it.

## Installation

Add this line to your application's Gemfile:

```ruby
gem 'fake_picture'
```

And then execute:

$ bundle install

Or install it yourself as:

$ gem install fake_picture

## Usage

###### FakePicture::Avatar:

```ruby
FakePicture::Avatar.man #=> /Users/username/workdirectory/fake_picture/lib/fake_picture/avatar/pack/man-4.jpg

FakePicture::Avatar.woman #=> /Users/username/workdirectory/fake_picture/lib/fake_picture/avatar/pack/woman-4.jpg
```

You can also call the method `person` if you want to get a random `avatar`:

```ruby
FakePicture::Avatar.person #=> "/Users/username/Workplace/fake_picture/lib/fake_picture/avatar/pack/woman-5.svg"
```

###### FakePicture::Blog:

```ruby
FakePicture::Blog.preview #=> /Users/username/workdirectory/fake_picture/lib/fake_picture/blog/pack/preview-4.jpg
```

###### FakePicture::People:

```ruby
FakePicture::People.man #=> /Users/username/workdirectory/fake_picture/lib/fake_picture/people/pack/man-4.jpg

FakePicture::People.woman #=> /Users/username/workdirectory/fake_picture/lib/fake_picture/people/pack/woman-4.jpg
```

###### FakePicture::company:

```ruby
FakePicture::Company.logo #=> /Users/username/workdirectory/fake_picture/lib/fake_picture/company/pack/logo-11.svg
```

#### As file:

You can also call a method `file` with the method name of this class if you wanna get a picture as a file for some actions, like this:

```ruby
FakePicture::People.file(:man) #=> #
```

#### As Base64:

You can also call a method `base64` with a method name of this class if you want to get the picture as a base64 encoded file for might be sending it somewhere, like this:

```ruby
FakePicture::People.base64(:man) #=> ""/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAwICQoJBwwKCgoNDQwOEh4TEhAQ\nEiQaGxUeKyYtLComKSkvNUQ6L.."
```

#### In factories:

```ruby
FactoryBot.define do
factory :gallery do
file { FakePicture::Blog.file(:preview) }
end
end
```

#### In specs:

```ruby
it 'some create user test' do
post :create, params: {
user: {
name: 'John',
avatar: FakePicture::Avatar.file(:man)
}
}
end
```

#### In seeds:

```ruby
User.create(name: 'John', avatar: FakePicture::Avatar.file(:man))
```

## Development

Run `rake spec` to run the tests. You can also run `rake console` for an interactive prompt that will allow you to experiment.

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 the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).

## Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/loqimean/fake_picture.

### To-Do
- [ ] add commerce pictures, like "products", and certain product types, e.g. "car", "phone" and like this, might be "cakes" 🙂

## License

The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).

## Thanks for your support!
[RailsJazz](https://github.com/railsjazz)