Skip to content

Instantly share code, notes, and snippets.

@jackhong
Last active December 29, 2015 17:09
Show Gist options
  • Save jackhong/7701758 to your computer and use it in GitHub Desktop.
Save jackhong/7701758 to your computer and use it in GitHub Desktop.

Support property operation information via FRCP

Existing implementation

To construct and send a configure message

topic.configure(membership: ['a', 'b', 'c'], name: 'bob', some_id: 100)

Serialise to XML

<configure>
  ...
  <props>
    <membership type='array'>
      <it type='string'>a</it>
      ...
    </membership>
    <name type='string'>bob</name>
    <some_id type='integer'>100</some_id>
  </props>
</configure>

Reconstruct message class from XML

message[:membership] will return ['a', 'b', 'c']

Potential solutions to carry operation information

Option 1:

Introduce additional data model, e.g. OmfCommon::Prop, and DSL method to init such model

topic.configure(
  membership: frcp_prop(['a', 'b', 'c'], op: 'union'),
  name: 'bob',
  some_id: 100
)

Where frcp_prop(['a', 'b', 'c'], op: 'union') init Prop object contains 'op' information.

By the time of serialisation, add additional attr accordingly.

<membership type='array' op='union'>
  <it type='string'>a</it>
  ...
</membership>

Then reconstruct to message from XML

message[:membership] will return OmfCommon::Prop, which says data is ['a', 'b', 'c'] and operation is 'union'

Option 2:

Extend message class to store operation information. Message construction will become:

topic.configure(
  { membership: ['a', 'b', 'c'], name: 'bob', some_id: 100 },
  { union: [:membership, ...], assign: [:name, :some_id ...] }
)

Same serialisation as option 1.

When received the message and reconstruct. Message instance will have { union: [:membership, ...], assign: [:name, :some_id ...] }

Then message[:membership] will still simply return ['a', 'b', 'c'], to find out operation information, we can do

message.op(:membership)

and it shall return 'union'

Extend RC DSL to pass operation

Last improvement, common to both options is to pass operation information to RC dsl. E.g:

configure :membership do |res, value, op|
  case op
  when 'assign'
    res.membership = value
  when 'union'
    res.memership += value
    res.membership.uniq!
  end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment