Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
hive-ruby
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
hive
hive-ruby
Commits
474ffd71
Unverified
Commit
474ffd71
authored
6 years ago
by
relativityboy
Committed by
GitHub
6 years ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #5 from steemit/4-basic-dependency-injection
4 basic dependency injection
parents
5d4b8377
06fe3f36
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/steem/api.rb
+17
-2
17 additions, 2 deletions
lib/steem/api.rb
test/steem/api_test.rb
+10
-0
10 additions, 0 deletions
test/steem/api_test.rb
with
27 additions
and
2 deletions
lib/steem/api.rb
+
17
−
2
View file @
474ffd71
...
@@ -70,9 +70,24 @@ module Steem
...
@@ -70,9 +70,24 @@ module Steem
end
end
end
end
# Override this if you want to use your own client.
# Override this if you want to just use your own client. Otherwise, inject
# the default using:
#
# Steem::Api.register default_rpc_client_class: MyClient
def
self
.
default_rpc_client_class
def
self
.
default_rpc_client_class
DEFAULT_RPC_CLIENT_CLASS
if
!!
@injected_dependencies
&&
!!
@injected_dependencies
[
:default_rpc_client_class
]
@injected_dependencies
[
:default_rpc_client_class
]
else
DEFAULT_RPC_CLIENT_CLASS
end
end
# Used for dependency injection. Currently, the only key supported is:
#
# `default_rpc_client_class`
def
self
.
register
(
register
)
@injected_dependencies
||=
{}
@injected_dependencies
=
@injected_dependencies
.
merge
register
end
end
def
initialize
(
options
=
{})
def
initialize
(
options
=
{})
...
...
This diff is collapsed.
Click to expand it.
test/steem/api_test.rb
+
10
−
0
View file @
474ffd71
...
@@ -65,6 +65,16 @@ module Steem
...
@@ -65,6 +65,16 @@ module Steem
end
end
end
end
def
test_dependency_injection
original_rpc_client_class
=
Api
.
default_rpc_client_class
Api
.
register
default_rpc_client_class:
RPC
::
HttpClient
assert_equal
RPC
::
HttpClient
,
Api
.
default_rpc_client_class
Api
.
register
default_rpc_client_class:
original_rpc_client_class
assert_equal
original_rpc_client_class
,
Api
.
default_rpc_client_class
end
def
test_inspect
def
test_inspect
assert_equal
"#<CondenserApi [@chain=steem, @methods=<85 elements>]>"
,
@api
.
inspect
assert_equal
"#<CondenserApi [@chain=steem, @methods=<85 elements>]>"
,
@api
.
inspect
end
end
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment