Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/mongoid/shell/properties/host.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def host
@host || begin
node = session.cluster.nodes.first
raise Mongoid::Shell::Errors::SessionNotConnectedError unless node
node.address == "localhost:27017" ? nil : node.address
node.address.original == "localhost:27017" ? nil : node.address.original
end
end

Expand Down
11 changes: 9 additions & 2 deletions lib/mongoid/shell/properties/password.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,18 @@ module Password
# current password
def password
@password || begin
return nil unless session.context.cluster.auth && session.context.cluster.auth.first
session.context.cluster.auth.first[1][1]
node = session.cluster.nodes.first
raise Mongoid::Shell::Errors::SessionNotConnectedError unless node
return nil unless node.credentials.has_key? db || node.credentials[db].empty?
node.credentials[db][1]
end
end

private
def db
@db || session.send(:current_database).name
end

end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/mongoid/shell/properties/primary.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def primary
raise Mongoid::Shell::Errors::SessionNotConnectedError unless session.cluster.nodes.any?
node = session.cluster.nodes.find(&:primary?)
raise Mongoid::Shell::Errors::MissingPrimaryNodeError unless node
node.address == "localhost:27017" ? nil : node.address
node.address.original == "localhost:27017" ? nil : node.address.original
end
end

Expand Down
11 changes: 9 additions & 2 deletions lib/mongoid/shell/properties/username.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,18 @@ module Username
# current username
def username
@username || begin
return nil unless session.context.cluster.auth && session.context.cluster.auth.first
session.context.cluster.auth.first[1][0]
node = session.cluster.nodes.first
raise Mongoid::Shell::Errors::SessionNotConnectedError unless node
return nil unless node.credentials.has_key? db || node.credentials[db].empty?
node.credentials[db][0]
end
end

private
def db
@db || session.send(:current_database).name
end

end
end
end
Expand Down
2 changes: 1 addition & 1 deletion mongoid-shell.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Gem::Specification.new do |s|
s.homepage = "http://github.com/dblock/mongoid-shell"
s.licenses = [ "MIT" ]
s.summary = "Derive shell commands from Mongoid configuration options."
s.add_dependency "mongoid", ">= 3.0.0"
s.add_dependency "mongoid", ">= 4.0.0.alpha1"
s.add_dependency "i18n"
end

Expand Down