# تحويل ملفات Ruby بسيطة إلى gem Ruby

**URL:** <https://meta.discourse.org/t/transforming-simple-ruby-files-into-a-ruby-gem/103399>\
**Category:** Development\
**Created:** [3 ديسمبر 2018، 9:56م UTC](https://meta.discourse.org/t/transforming-simple-ruby-files-into-a-ruby-gem/103399 "2018-12-03T21:56:30Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![blake](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/blake/32/157322_2.png) [@blake](https://meta.discourse.org/u/blake)\
**Post date:** [7 ديسمبر 2018، 8:15م UTC](https://meta.discourse.org/t/transforming-simple-ruby-files-into-a-ruby-gem/103399/4 "2018-12-07T20:15:30Z")

</div>

> [@SebastianADW](#):
>
> Do you have any idea why its not working?

Not exactly, but I still think it is dependency issues and not specifying the gems correctly.

> [@SebastianADW](#):
>
> I also tried to specify the version of the gem like that `gem "twitter", "6.2"`

I think it has to be the full version number like `6.2.0`. I also don’t think you need to specify “bundler” or “net”.

Apparently when writing a plugin you have to go through dependency hell 🔥 to get it all working and happy. Basically the workflow I go though is start with the main gem that I want. In this case it is the twitter gem. Make sure this one is always listed as the last gem in your plugin.rb file.

```
gem 'twitter', '6.2.0', { require: false }

```

Then I look at all the [runtime dependencies for this gem](https://rubygems.org/gems/twitter) and ONE AT A TIME list each dependency with each subdependency above the twitter gem. Run `bundle exec rails s` between each dependency and check for `(Gem::MissingSpecError)` to know which dependency to add next.

Apparently the addressable gem (2.5.2, instead of 2.3.8) is already required by a discourse gem, so it should be safe to ignore. (You can run `gem dependency addressable --reverse-dependencies` to see which gems require it).

Your plugin.rb should look something like:

```plaintext
gem 'buftok', '0.2.0', { require: false }
gem 'equalizer', '0.0.11', { require: false }
gem 'domain_name', '0.5.20180417', { require: false }
gem 'http-cookie', '1.0.3', { require: false }
gem 'http-form_data', '2.0.0', { require: false }
gem 'http_parser.rb', '0.6.0', { require: false }
gem 'http', '3.3.0', { require: false }
gem 'memoizable', '0.4.2', { require: false }
gem 'naught', '1.1.0', { require: false }
gem 'simple_oauth', '0.3.1', { require: false }
gem 'twitter', '6.2.0', { require: false }

#gem 'addressable', '2.3.8', { require: false } # Already required in Discourse
#gem 'multipart-post', '2.0.0', { require: false } # Already required in Discourse

require 'twitter'

client = Twitter::REST::Client.new do |config|
  config.consumer_key = "YOUR_CONSUMER_KEY"
  config.consumer_secret = "YOUR_CONSUMER_SECRET"
  config.access_token = "YOUR_ACCESS_TOKEN"
  config.access_token_secret = "YOUR_ACCESS_SECRET"
end

```

`bundle exec rails s` should now run successfully and you can now write your plugin and break things out into separate files if you’d like, but the gem dependencies should stay in the plugin.rb file.

---

_[View the full topic](https://meta.discourse.org/t/transforming-simple-ruby-files-into-a-ruby-gem/103399)._
