rutty 2.3.1 → 2.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.3.1
1
+ 2.3.2
data/bin/rutty CHANGED
@@ -69,13 +69,6 @@ command :list_nodes do |c|
69
69
  # TODO: Make tag searching AND or OR, not just OR
70
70
  c.syntax = "rutty list_nodes [options]"
71
71
  c.summary = "List nodes according to [options]."
72
- c.description = "#{c.summary} Options are the same as add_node"
73
-
74
- c.example "List all nodes", "rutty list_nodes"
75
- c.example "List all nodes that are tagged with 'web' OR 'db'", "rutty list_nodes --tags web,db"
76
- c.example "List all nodes configued to SSH into port 2222", "rutty list_nodes --port 2222"
77
-
78
- add_filter_options.call(c)
79
72
 
80
73
  c.when_called do |args, options|
81
74
  $r.list_nodes args, options
data/lib/rutty/nodes.rb CHANGED
@@ -94,10 +94,10 @@ module Rutty
94
94
 
95
95
  filter = nil
96
96
 
97
- if query_str =~ /^\w$/
97
+ if query_str =~ /^[A-Za-z_-]+$/
98
98
  # Single tag query, no need to fire up the parser
99
- filter = Procs::SingleTagQuery.new { |n| n.has_tag? "#{$1}" }
100
- elsif query_str =~ /^(?:\w,?)+$/
99
+ filter = Procs::SingleTagQuery.new { |n| !n.has_tag? query_str }
100
+ elsif query_str =~ /^(?:[A-Za-z_-]+,?)+$/
101
101
  # Old-style comma-separated tag query. Still no
102
102
  # need to fire up the parser, just additively compare.
103
103
  tags = query_str.split(',')
data/lib/rutty/version.rb CHANGED
@@ -9,7 +9,7 @@ module Rutty
9
9
  module Version
10
10
  MAJOR = 2
11
11
  MINOR = 3
12
- PATCH = 1
12
+ PATCH = 2
13
13
  BUILD = nil
14
14
 
15
15
  STRING = [MAJOR, MINOR, PATCH, BUILD].compact.join('.')
data/rutty.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{rutty}
8
- s.version = "2.3.1"
8
+ s.version = "2.3.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Josh Lindsey"]
data/test/helper.rb CHANGED
@@ -44,3 +44,12 @@ class Test::Unit::TestCase
44
44
  end
45
45
  end
46
46
  end
47
+
48
+ class Class
49
+ def publicize_methods
50
+ saved_private_instance_methods = self.private_instance_methods
51
+ self.class_eval { public *saved_private_instance_methods }
52
+ yield
53
+ self.class_eval { private *saved_private_instance_methods }
54
+ end
55
+ end
data/test/test_nodes.rb CHANGED
@@ -45,6 +45,7 @@ class TestNodes < Test::Unit::TestCase
45
45
  :user => 'example',
46
46
  :keypath => '/home/example/.ssh/id_rsa.pem',
47
47
  :tags => %w(broken test example)
48
+
48
49
  @nodes = Rutty::Nodes.new [@node1, @node2, @node3]
49
50
  end
50
51
 
@@ -54,6 +55,35 @@ class TestNodes < Test::Unit::TestCase
54
55
  assert_contains @nodes, @node1, @node2
55
56
  end
56
57
 
58
+ should "return the correct Proc type for each query string type" do
59
+ Rutty::Nodes.publicize_methods do
60
+ assert_instance_of Rutty::Procs::SingleTagQuery, @nodes.get_tag_query_filter('foo')
61
+ assert_instance_of Rutty::Procs::MultipleTagQuery, @nodes.get_tag_query_filter('foo,bar')
62
+ assert_instance_of Rutty::Procs::SqlLikeTagQuery, @nodes.get_tag_query_filter("'foo' AND 'bar' OR 'baz'")
63
+ end
64
+ end
65
+
66
+ should "generate the correct Proc string to eval" do
67
+ Rutty::Nodes.publicize_methods do
68
+ # New sql-like tag query. Need the parser for this.
69
+ require 'treetop'
70
+ require 'rutty/treetop/syntax_nodes'
71
+ require 'rutty/treetop/tag_query'
72
+
73
+ parser = TagQueryGrammarParser.new
74
+
75
+ proc_str = @nodes.recursive_build_query_proc_string parser.parse("'foo' AND 'bar' OR 'baz'").elements
76
+ proc_str = proc_str.rstrip << ') }'
77
+
78
+ assert_equal "Procs::SqlLikeTagQuery.new { |n| !(n.has_tag?('foo') && n.has_tag?('bar') || n.has_tag?('baz')) }", proc_str
79
+
80
+ proc_str = @nodes.recursive_build_query_proc_string parser.parse("'test' OR ('example' AND 'foo')").elements
81
+ proc_str = proc_str.rstrip << ') }'
82
+
83
+ assert_equal "Procs::SqlLikeTagQuery.new { |n| !(n.has_tag?('test') || (n.has_tag?('example') && n.has_tag?('foo'))) }", proc_str
84
+ end
85
+ end
86
+
57
87
  should "filter out nodes matching provided criteria" do
58
88
  assert_equal [@node1, @node2], @nodes.filter(OpenStruct.new :port => 22)
59
89
  assert_equal [@node2], @nodes.filter(OpenStruct.new :user => 'google')
@@ -68,6 +98,10 @@ class TestNodes < Test::Unit::TestCase
68
98
  filtered = @nodes.filter(OpenStruct.new :tags => 'fake')
69
99
  assert_equal 2, filtered.length
70
100
  assert_equal [@node1, @node2], filtered
101
+
102
+ filtered = @nodes.filter(OpenStruct.new :tags => 'google')
103
+ assert_equal 1, filtered.length
104
+ assert_equal [@node2], filtered
71
105
  end
72
106
 
73
107
  should "correctly filter on a comma-separated list of tags and return the correct node(s)" do
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rutty
3
3
  version: !ruby/object:Gem::Version
4
- hash: 1
4
+ hash: 7
5
5
  prerelease: false
6
6
  segments:
7
7
  - 2
8
8
  - 3
9
- - 1
10
- version: 2.3.1
9
+ - 2
10
+ version: 2.3.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Josh Lindsey