Why do I need to explicitly include a gem when it's already a dependency of another gem I'm using?
up vote
0
down vote
favorite
I have created a gem/Rails engine (let's call it my_rails_gem) that depends on another gem; specifically, the composite_primary_keys gem (some of the models need it). So in the .gemspec file, I have
Gem::Specification.new do |s|
#...
s.add_dependency 'composite_primary_keys'
The problem is that when I include the my_rails_gem in another Rails project's Gemfile and try to use the models, I get errors about composite_primary_keys' functionality. I must also explicitly add gem 'composite_primary_keys'
to the app's Gemfile for it to function correctly.
Why is this? Isn't this the whole point of Bundle and gem dependencies? I want to take the burden off the developer using my_rails_gem to remember to have to include composite_primary_keys, but this is specifically preventing that. Am I doing something wrong, or are my expectations/understanding wrong?
ruby-on-rails rubygems dependency-management
add a comment |
up vote
0
down vote
favorite
I have created a gem/Rails engine (let's call it my_rails_gem) that depends on another gem; specifically, the composite_primary_keys gem (some of the models need it). So in the .gemspec file, I have
Gem::Specification.new do |s|
#...
s.add_dependency 'composite_primary_keys'
The problem is that when I include the my_rails_gem in another Rails project's Gemfile and try to use the models, I get errors about composite_primary_keys' functionality. I must also explicitly add gem 'composite_primary_keys'
to the app's Gemfile for it to function correctly.
Why is this? Isn't this the whole point of Bundle and gem dependencies? I want to take the burden off the developer using my_rails_gem to remember to have to include composite_primary_keys, but this is specifically preventing that. Am I doing something wrong, or are my expectations/understanding wrong?
ruby-on-rails rubygems dependency-management
How are you consuming it in your application? Do yourequire
it anywhere, manually or via an autoloading mechanism?
– Dave Newton
Nov 9 at 22:29
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have created a gem/Rails engine (let's call it my_rails_gem) that depends on another gem; specifically, the composite_primary_keys gem (some of the models need it). So in the .gemspec file, I have
Gem::Specification.new do |s|
#...
s.add_dependency 'composite_primary_keys'
The problem is that when I include the my_rails_gem in another Rails project's Gemfile and try to use the models, I get errors about composite_primary_keys' functionality. I must also explicitly add gem 'composite_primary_keys'
to the app's Gemfile for it to function correctly.
Why is this? Isn't this the whole point of Bundle and gem dependencies? I want to take the burden off the developer using my_rails_gem to remember to have to include composite_primary_keys, but this is specifically preventing that. Am I doing something wrong, or are my expectations/understanding wrong?
ruby-on-rails rubygems dependency-management
I have created a gem/Rails engine (let's call it my_rails_gem) that depends on another gem; specifically, the composite_primary_keys gem (some of the models need it). So in the .gemspec file, I have
Gem::Specification.new do |s|
#...
s.add_dependency 'composite_primary_keys'
The problem is that when I include the my_rails_gem in another Rails project's Gemfile and try to use the models, I get errors about composite_primary_keys' functionality. I must also explicitly add gem 'composite_primary_keys'
to the app's Gemfile for it to function correctly.
Why is this? Isn't this the whole point of Bundle and gem dependencies? I want to take the burden off the developer using my_rails_gem to remember to have to include composite_primary_keys, but this is specifically preventing that. Am I doing something wrong, or are my expectations/understanding wrong?
ruby-on-rails rubygems dependency-management
ruby-on-rails rubygems dependency-management
asked Nov 9 at 21:59
istrasci
63911236
63911236
How are you consuming it in your application? Do yourequire
it anywhere, manually or via an autoloading mechanism?
– Dave Newton
Nov 9 at 22:29
add a comment |
How are you consuming it in your application? Do yourequire
it anywhere, manually or via an autoloading mechanism?
– Dave Newton
Nov 9 at 22:29
How are you consuming it in your application? Do you
require
it anywhere, manually or via an autoloading mechanism?– Dave Newton
Nov 9 at 22:29
How are you consuming it in your application? Do you
require
it anywhere, manually or via an autoloading mechanism?– Dave Newton
Nov 9 at 22:29
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
I believe the reason that the dependent gem is not automatically required is so that the user of your gem (you) have the option of requiring the dependent gem. There are reasons for that, but it's a bit of a longer conversation.
If you want the dependent gem to be required automatically when you include your gem, then in your my_rails_gem.rb
file (in your lib
directory) you can do:
require 'composite_primary_keys'
I believe that ought to do the trick for you. At least, that's how I do it.
Also, if the dependent gem has stylesheet and javascript assets that you want to include (I suspect composite_primary_keys
does not), you'll need to add the appropriate directives to your my_rails_gem.js
and my_rails_gem.sass
(or whatever templating engine you use) files.
Thanks, I'll try this.
– istrasci
Nov 9 at 22:49
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
I believe the reason that the dependent gem is not automatically required is so that the user of your gem (you) have the option of requiring the dependent gem. There are reasons for that, but it's a bit of a longer conversation.
If you want the dependent gem to be required automatically when you include your gem, then in your my_rails_gem.rb
file (in your lib
directory) you can do:
require 'composite_primary_keys'
I believe that ought to do the trick for you. At least, that's how I do it.
Also, if the dependent gem has stylesheet and javascript assets that you want to include (I suspect composite_primary_keys
does not), you'll need to add the appropriate directives to your my_rails_gem.js
and my_rails_gem.sass
(or whatever templating engine you use) files.
Thanks, I'll try this.
– istrasci
Nov 9 at 22:49
add a comment |
up vote
1
down vote
I believe the reason that the dependent gem is not automatically required is so that the user of your gem (you) have the option of requiring the dependent gem. There are reasons for that, but it's a bit of a longer conversation.
If you want the dependent gem to be required automatically when you include your gem, then in your my_rails_gem.rb
file (in your lib
directory) you can do:
require 'composite_primary_keys'
I believe that ought to do the trick for you. At least, that's how I do it.
Also, if the dependent gem has stylesheet and javascript assets that you want to include (I suspect composite_primary_keys
does not), you'll need to add the appropriate directives to your my_rails_gem.js
and my_rails_gem.sass
(or whatever templating engine you use) files.
Thanks, I'll try this.
– istrasci
Nov 9 at 22:49
add a comment |
up vote
1
down vote
up vote
1
down vote
I believe the reason that the dependent gem is not automatically required is so that the user of your gem (you) have the option of requiring the dependent gem. There are reasons for that, but it's a bit of a longer conversation.
If you want the dependent gem to be required automatically when you include your gem, then in your my_rails_gem.rb
file (in your lib
directory) you can do:
require 'composite_primary_keys'
I believe that ought to do the trick for you. At least, that's how I do it.
Also, if the dependent gem has stylesheet and javascript assets that you want to include (I suspect composite_primary_keys
does not), you'll need to add the appropriate directives to your my_rails_gem.js
and my_rails_gem.sass
(or whatever templating engine you use) files.
I believe the reason that the dependent gem is not automatically required is so that the user of your gem (you) have the option of requiring the dependent gem. There are reasons for that, but it's a bit of a longer conversation.
If you want the dependent gem to be required automatically when you include your gem, then in your my_rails_gem.rb
file (in your lib
directory) you can do:
require 'composite_primary_keys'
I believe that ought to do the trick for you. At least, that's how I do it.
Also, if the dependent gem has stylesheet and javascript assets that you want to include (I suspect composite_primary_keys
does not), you'll need to add the appropriate directives to your my_rails_gem.js
and my_rails_gem.sass
(or whatever templating engine you use) files.
answered Nov 9 at 22:16
jvillian
11.7k52135
11.7k52135
Thanks, I'll try this.
– istrasci
Nov 9 at 22:49
add a comment |
Thanks, I'll try this.
– istrasci
Nov 9 at 22:49
Thanks, I'll try this.
– istrasci
Nov 9 at 22:49
Thanks, I'll try this.
– istrasci
Nov 9 at 22:49
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53233786%2fwhy-do-i-need-to-explicitly-include-a-gem-when-its-already-a-dependency-of-anot%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
How are you consuming it in your application? Do you
require
it anywhere, manually or via an autoloading mechanism?– Dave Newton
Nov 9 at 22:29