Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Simple object transpositions using hash map of attributes. Particularly useful when working with remote apis, and mapping from a remote structure, to a localized structure.
You want to map a remote post model with mostly camel cased method names, to a local active record model.
class RemotePost < ::OpenStruct
include ::Transpose::Transposable
transposer "Post", {
:Id => :remote_id,
:Title => :title,
}
end
And back again
class Post < ::ActiveRecord::Base
include ::Transpose::Transposable
transposer "RemotePost", {
:remote_id => :Id,
:title => :Title
}
end
So you do
remote = ::RemotePost.new(:Id => '1234', :Title => "Nocturne In e Flat Op 9 No.2" )
local = remote.transpose(Post).save
#=> #<Post id="1234", title="Nocturne In e Flat Op 9 No.2">
Supports passing an instance as well via transpose_instance
post = Post.new(:title => "prebuilt title")
remote_post = ::RemotePost.new(:Id => 1234)
remote_post.transpose_instance(post)
#=> #<Post id="1234", title="prebuilt title">
Implementing a good solution for working with external api gems, when classes have already been defined. I.E. abstracting injecting the transposer into remote model.
Maybe support for getter and setter value strategies, i.e. right now you cant map an object to a hash, since it sets/gets via send. However, Im not sure that should be a concern of this gem, as that would likely kill much of the simplicity which Id like to keep.
Maybe coercion of attributes via passing lambda as value
Add this line to your application's Gemfile:
gem 'transpose'
And then execute:
$ bundle
Or install it yourself as:
$ gem install transpose
TODO: Write usage instructions here
git checkout -b my-new-feature
)git commit -am 'Add some feature'
)git push origin my-new-feature
)FAQs
Unknown package
We found that transpose demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.