Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement :struct options for properties. #30

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -366,14 +366,12 @@ Twins can also map hash properties, e.g. from a deeply nested serialized JSON co
album.permissions #=> {admin: {read: true, write: true}, user: {destroy: false}}
```

Map that using the `Struct` module.
Map that using the `:struct` option that automatically adds `Disposable::Twin::Struct` feature.

```ruby
class AlbumTwin < Disposable::Twin
property :permissions do
include Struct
property :admin do
include Struct
property :permissions, struct: true do
property :admin, struct: true do
property :read
property :write
end
Expand Down
8 changes: 7 additions & 1 deletion lib/disposable/twin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,13 @@ def property(name, options={}, &block)

options[:nested] = options.delete(:twin) if options[:twin]

super(name, options, &block).tap do |definition|
class_block = proc do
require 'disposable/twin/struct'
include Disposable::Twin::Struct if options[:struct]
class_eval(&block)
end if block

super(name, options, &class_block).tap do |definition|
create_accessors(name, definition)
end
end
Expand Down