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?










share|improve this question






















  • 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















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?










share|improve this question






















  • 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













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?










share|improve this question













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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 9 at 21:59









istrasci

63911236




63911236












  • 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
















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












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.






share|improve this answer





















  • Thanks, I'll try this.
    – istrasci
    Nov 9 at 22:49











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















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

























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.






share|improve this answer





















  • Thanks, I'll try this.
    – istrasci
    Nov 9 at 22:49















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.






share|improve this answer





















  • Thanks, I'll try this.
    – istrasci
    Nov 9 at 22:49













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.






share|improve this answer












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.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 9 at 22:16









jvillian

11.7k52135




11.7k52135












  • 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




Thanks, I'll try this.
– istrasci
Nov 9 at 22:49


















draft saved

draft discarded




















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

Schultheiß

Liste der Kulturdenkmale in Wilsdruff

Android Play Services Check