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

Add table-style filter utility #681

Merged
merged 4 commits into from
Apr 28, 2016
Merged

Add table-style filter utility #681

merged 4 commits into from
Apr 28, 2016

Conversation

arlimus
Copy link
Contributor

@arlimus arlimus commented Apr 25, 2016

This adds a new filter utility inspired by Stephan's filter_array. It is much more complex, however, as it aims to:

  • only filter on known fields, not unknown ones
  • fields in the source map can be strings or symbols
  • optimized for printing the filtering chain
  • can act on any type of field, including nil
  • extend the owner class with accessor methods for this filter
  • can retrieve entries as an embedded object with easy accessors to all fields

WIP: This is wip and discussions are highly welcome!

@arlimus arlimus added the Type: Enhancement Improves an existing feature label Apr 25, 2016
@vjeffrey
Copy link

read through it a couple times, I'm thumbs up - the tests helped me understand the intent of the code - makes sense!

@chris-rock
Copy link
Contributor

I'd like to add an example using the inspec shell

inspec> xinetd_conf.services
=> ["time", "chargen", "daytime", "echo", "discard"]
inspec> xinetd_conf.where { service == 'echo' }
=> Xinetd config /etc/xinetd.conf with service == "echo"
inspec> xinetd_conf.where { service == 'echo' }.params
=> [{"disable"=>"yes", "type"=>"INTERNAL", "id"=>"echo-dgram", "socket_type"=>"dgram", "protocol"=>"udp", "user"=>"root", "wait"=>"yes", "service"=>"echo"}]
inspec> xinetd_conf.socket_types
=> ["dgram", "dgram", "dgram", "dgram", "dgram"]
inspec> xinetd_conf.where { socket_type == 'dgram' }
=> Xinetd config /etc/xinetd.conf with socket_type == "dgram"
inspec> xinetd_conf.where { socket_type == 'dgram' }.params
=> [{"disable"=>"yes", "type"=>"INTERNAL", "id"=>"time-dgram", "socket_type"=>"dgram", "protocol"=>"udp", "user"=>"root", "wait"=>"yes", "service"=>"time"},
 {"disable"=>"yes", "type"=>"INTERNAL", "id"=>"chargen-dgram", "socket_type"=>"dgram", "protocol"=>"udp", "user"=>"root", "wait"=>"yes", "service"=>"chargen"},
 {"disable"=>"yes", "type"=>"INTERNAL", "id"=>"daytime-dgram", "socket_type"=>"dgram", "protocol"=>"udp", "user"=>"root", "wait"=>"yes", "service"=>"daytime"},
 {"disable"=>"yes", "type"=>"INTERNAL", "id"=>"echo-dgram", "socket_type"=>"dgram", "protocol"=>"udp", "user"=>"root", "wait"=>"yes", "service"=>"echo"},
 {"disable"=>"yes", "type"=>"INTERNAL", "id"=>"discard-dgram", "socket_type"=>"dgram", "protocol"=>"udp", "user"=>"root", "wait"=>"yes", "service"=>"discard"}]

@chris-rock chris-rock changed the title WIP add table-style filter utility Add table-style filter utility Apr 28, 2016
@chris-rock chris-rock merged commit c0dc10e into master Apr 28, 2016
@chris-rock chris-rock deleted the dr/altfilter branch April 28, 2016 21:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Enhancement Improves an existing feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants