command-designer 0.0.1 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5b4550a3e11afffcbf1dd9804945b39f0bb45196
4
- data.tar.gz: 4aa3ccedd87418cdd5834e8da9a408852c6e88d7
3
+ metadata.gz: 1ac766aaf18cfc1096dc731cb63e3b885dc4e60f
4
+ data.tar.gz: a3626a4a5752ac12a185c4440647e52ea48d03a9
5
5
  SHA512:
6
- metadata.gz: 5d5a3ab75bf8a0bfadae14127f5ee0954a3c622d0c9dc74ab24451cb715905aec780586401086336a6dd4a2fd09184928fa92c5afa5e465b7335a4947eb58fc7
7
- data.tar.gz: fd22e9de7de656f964d737afccc921aac5cb0a4c27270b180d5c45c8131e99b4e8c7d55e5cf3047da84080dc80cdd824a72822053c757d1cf5df35d1d715b913
6
+ metadata.gz: dbe9963b7cfb1c563cccc034ee73beb3a4034b7714491e78d30183f459be733e48a3c890343ad2777b25923747f9b12ed0eba3138823d1a2c3b6fa95ad5a5f20
7
+ data.tar.gz: d0b61cea7257928d798ee443a0b66b6f74fbc18ea59d509da506004a17e13e1af20f121c9c0294e17cec88e7b9f685eec8b746d55ef514d53ac5926d53671db0
@@ -4,5 +4,5 @@ Copyright 2014 Michal Papis <mpapis@gmail.com>
4
4
  See the file LICENSE for copying permission.
5
5
  =end
6
6
 
7
- class CommandDesigner
8
- end
7
+ require "command-designer/version"
8
+ require "command-designer/dsl"
@@ -0,0 +1,56 @@
1
+ =begin
2
+ Copyright 2014 Michal Papis <mpapis@gmail.com>
3
+
4
+ See the file LICENSE for copying permission.
5
+ =end
6
+
7
+ require "shellwords"
8
+ require "command-designer/version"
9
+
10
+ # A concpet of command that can be extended multiple times
11
+ #
12
+ # @example
13
+ #
14
+ # command = CommandDesigner::Command.new("test")
15
+ # command.change {|command| "env #{command}" }
16
+ # command.command # => "env test"
17
+ #
18
+ class CommandDesigner::Command
19
+
20
+ # @return [String] current value of the command
21
+ attr_reader :command
22
+
23
+ # @return [Array] initial value of the command and parameters
24
+ attr_reader :initial_command
25
+
26
+ # initialize +command+ and +initial_command+
27
+ # @param args [Array<String>] The command name to build upon
28
+ def initialize(*args)
29
+ @initial_command = args || []
30
+ reset
31
+ end
32
+
33
+ # reset command to it's initial state
34
+ def reset
35
+ @command = Shellwords.join(@initial_command)
36
+ end
37
+
38
+ # Yields a block to change the command
39
+ # @yield [command] a block to change the command
40
+ # @yieldparam command [String] the current command
41
+ # @return [String] the new command
42
+ def change(&block)
43
+ @command = yield @command
44
+ end
45
+
46
+ # @return [String] just the first part of the command: +command_name+
47
+ def command_name
48
+ @initial_command.first
49
+ end
50
+
51
+ # @return [Boolean] true if other object equals command_name, false otherwise
52
+ def ==(other)
53
+ self.command_name == other
54
+ end
55
+
56
+ end
@@ -0,0 +1,23 @@
1
+ =begin
2
+ Copyright 2014 Michal Papis <mpapis@gmail.com>
3
+
4
+ See the file LICENSE for copying permission.
5
+ =end
6
+
7
+ require "command-designer/command"
8
+ require "context-filters"
9
+
10
+ # Add support for +command+ in +Context+ using +Filters+
11
+ class CommandDesigner::Dsl < ContextFilters::Context
12
+
13
+ # evaluates the given command_name in current context (applies matching filters)
14
+ # @param command_name [String] the command name to evaluate
15
+ # @param args [String] rest of command arguments
16
+ # @return [String] the evaluated value of command name
17
+ def command(command_name, *args)
18
+ cmd = CommandDesigner::Command.new(command_name, *args)
19
+ evaluate_filters(cmd, :change)
20
+ cmd.command
21
+ end
22
+
23
+ end
@@ -1,3 +1,5 @@
1
+ # Build command text based on multiple filters
1
2
  class CommandDesigner
2
- VERSION = "0.0.1"
3
+ # version of the command-designer gem
4
+ VERSION = "0.8.0"
3
5
  end
@@ -0,0 +1,29 @@
1
+ =begin
2
+ Copyright 2014 Michal Papis <mpapis@gmail.com>
3
+
4
+ See the file LICENSE for copying permission.
5
+ =end
6
+
7
+ require "test_helper"
8
+ require "command-designer/command"
9
+
10
+ describe CommandDesigner::Command do
11
+ subject do
12
+ CommandDesigner::Command.allocate
13
+ end
14
+
15
+ it "initializes command" do
16
+ subject.send(:initialize, "true")
17
+ subject.command.must_equal("true")
18
+ subject.initial_command.must_equal(["true"])
19
+ end
20
+
21
+ it "builds and resets the command" do
22
+ subject.send(:initialize, "true")
23
+ subject.change {|command| "env #{command}"}
24
+ subject.command.must_equal("env true")
25
+ subject.reset
26
+ subject.command.must_equal("true")
27
+ end
28
+
29
+ end
@@ -0,0 +1,53 @@
1
+ =begin
2
+ Copyright 2014 Michal Papis <mpapis@gmail.com>
3
+
4
+ See the file LICENSE for copying permission.
5
+ =end
6
+
7
+ require "test_helper"
8
+ require "command-designer/dsl"
9
+
10
+ describe CommandDesigner::Dsl do
11
+ subject do
12
+ CommandDesigner::Dsl.new
13
+ end
14
+
15
+ describe "top level" do
16
+
17
+ it "handles top level commands" do
18
+ subject.command("true").must_equal("true")
19
+ end
20
+
21
+ it "handles filtered commands" do
22
+ subject.filter(nil) do |command| "env #{command}" end
23
+ subject.command("true").must_equal("env true")
24
+ subject.command("false").must_equal("env false")
25
+ end
26
+
27
+ it "does not filter commands that are not in context" do
28
+ subject.filter(nil, :commands) do |command| "command #{command}" end
29
+ subject.command("true").must_equal("true")
30
+ end
31
+
32
+ it "does not call evaluate_command for no filters" do
33
+ subject.expects(:evaluate_filters).once
34
+ subject.command("true")
35
+ end
36
+
37
+ it "handles filtered targeted commands" do
38
+ subject.filter(nil, {:target => "true"}) do |command| "env #{command}" end
39
+ subject.command("false").must_equal("false")
40
+ subject.command("true").must_equal("env true")
41
+ end
42
+
43
+ it "handles filtered targeted commands in context" do
44
+ subject.filter(nil, {:target => "true"}) do |command| "env #{command}" end
45
+ subject.in_context({:a=>3}) do
46
+ subject.command("false").must_equal("false")
47
+ subject.command("true").must_equal("env true")
48
+ end
49
+ end
50
+
51
+ end #"top level"
52
+
53
+ end
@@ -0,0 +1,33 @@
1
+ =begin
2
+ Copyright 2014 Michal Papis <mpapis@gmail.com>
3
+
4
+ See the file LICENSE for copying permission.
5
+ =end
6
+
7
+ require "rubygems"
8
+
9
+ if
10
+ RUBY_VERSION == "2.0.0" && # check Gemfile
11
+ $0 != "-e" # do not do that in guard
12
+ then
13
+ require "coveralls"
14
+ require "simplecov"
15
+
16
+ SimpleCov.start do
17
+ formatter SimpleCov::Formatter::MultiFormatter[
18
+ SimpleCov::Formatter::HTMLFormatter,
19
+ Coveralls::SimpleCov::Formatter,
20
+ ]
21
+ command_name "Unit Tests"
22
+ add_filter "/test/"
23
+ end
24
+
25
+ Coveralls.noisy = true unless ENV["CI"]
26
+ end
27
+
28
+ # Autoload all lib/**/*.rb files so simplecov does not misses anything
29
+ Dir[File.expand_path("../../lib/**/*.rb", __FILE__)].each{|f| require f }
30
+
31
+ require "minitest/autorun" unless $0=="-e" # skip in guard
32
+ require "minitest/unit"
33
+ require "mocha/setup"
metadata CHANGED
@@ -1,41 +1,117 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: command-designer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michal Papis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-13 00:00:00.000000000 Z
11
+ date: 2014-10-17 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: context-filters
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '0.9'
20
+ - - '>='
21
+ - !ruby/object:Gem::Version
22
+ version: 0.9.2
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '0.9'
30
+ - - '>='
31
+ - !ruby/object:Gem::Version
32
+ version: 0.9.2
33
+ - !ruby/object:Gem::Dependency
34
+ name: guard
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ~>
38
+ - !ruby/object:Gem::Version
39
+ version: '2.6'
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ~>
45
+ - !ruby/object:Gem::Version
46
+ version: '2.6'
47
+ - !ruby/object:Gem::Dependency
48
+ name: guard-minitest
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: '2.3'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ~>
59
+ - !ruby/object:Gem::Version
60
+ version: '2.3'
61
+ - !ruby/object:Gem::Dependency
62
+ name: guard-yard
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ~>
66
+ - !ruby/object:Gem::Version
67
+ version: '2.1'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ~>
73
+ - !ruby/object:Gem::Version
74
+ version: '2.1'
13
75
  - !ruby/object:Gem::Dependency
14
76
  name: minitest
15
77
  requirement: !ruby/object:Gem::Requirement
16
78
  requirements:
17
- - - "~>"
79
+ - - ~>
18
80
  - !ruby/object:Gem::Version
19
81
  version: '5.4'
20
82
  type: :development
21
83
  prerelease: false
22
84
  version_requirements: !ruby/object:Gem::Requirement
23
85
  requirements:
24
- - - "~>"
86
+ - - ~>
25
87
  - !ruby/object:Gem::Version
26
88
  version: '5.4'
89
+ - !ruby/object:Gem::Dependency
90
+ name: mocha
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ~>
94
+ - !ruby/object:Gem::Version
95
+ version: '1.1'
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ~>
101
+ - !ruby/object:Gem::Version
102
+ version: '1.1'
27
103
  - !ruby/object:Gem::Dependency
28
104
  name: rake
29
105
  requirement: !ruby/object:Gem::Requirement
30
106
  requirements:
31
- - - "~>"
107
+ - - ~>
32
108
  - !ruby/object:Gem::Version
33
109
  version: '10.3'
34
110
  type: :development
35
111
  prerelease: false
36
112
  version_requirements: !ruby/object:Gem::Requirement
37
113
  requirements:
38
- - - "~>"
114
+ - - ~>
39
115
  - !ruby/object:Gem::Version
40
116
  version: '10.3'
41
117
  description:
@@ -46,7 +122,12 @@ extensions: []
46
122
  extra_rdoc_files: []
47
123
  files:
48
124
  - lib/command-designer.rb
125
+ - lib/command-designer/command.rb
126
+ - lib/command-designer/dsl.rb
49
127
  - lib/command-designer/version.rb
128
+ - test/command-designer/command_test.rb
129
+ - test/command-designer/dsl_test.rb
130
+ - test/test_helper.rb
50
131
  homepage: https://github.com/remote-exec/command-designer
51
132
  licenses:
52
133
  - MIT
@@ -57,18 +138,22 @@ require_paths:
57
138
  - lib
58
139
  required_ruby_version: !ruby/object:Gem::Requirement
59
140
  requirements:
60
- - - ">="
141
+ - - '>='
61
142
  - !ruby/object:Gem::Version
62
143
  version: 1.9.3
63
144
  required_rubygems_version: !ruby/object:Gem::Requirement
64
145
  requirements:
65
- - - ">="
146
+ - - '>='
66
147
  - !ruby/object:Gem::Version
67
148
  version: '0'
68
149
  requirements: []
69
150
  rubyforge_project:
70
- rubygems_version: 2.4.2
151
+ rubygems_version: 2.2.2
71
152
  signing_key:
72
153
  specification_version: 4
73
154
  summary: Build command text based on multiple filters
74
- test_files: []
155
+ test_files:
156
+ - test/command-designer/command_test.rb
157
+ - test/command-designer/dsl_test.rb
158
+ - test/test_helper.rb
159
+ has_rdoc: