rprogram 0.2.3 → 0.3.0

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.
@@ -1 +0,0 @@
1
- require 'rprogram/extensions/meta'
@@ -1,2 +0,0 @@
1
- require 'rprogram/nameable/class_methods'
2
- require 'rprogram/nameable/nameable'
@@ -1,84 +0,0 @@
1
- module RProgram
2
- module Nameable
3
- module ClassMethods
4
- #
5
- # @return [String]
6
- # The name of the program.
7
- #
8
- def program_name
9
- @program_name ||= nil
10
- end
11
-
12
- #
13
- # @return [Array]
14
- # The program's aliases.
15
- #
16
- def program_aliases
17
- @program_aliases ||= []
18
- end
19
-
20
- #
21
- # Combines program_name with program_aliases.
22
- #
23
- # @return [Array]
24
- # Names the program is known by.
25
- #
26
- def program_names
27
- ([program_name] + program_aliases).compact
28
- end
29
-
30
- #
31
- # Sets the program name for the class.
32
- #
33
- # @param [String, Symbol] name
34
- # The new program name.
35
- #
36
- # @example
37
- # name_program 'ls'
38
- #
39
- def name_program(name)
40
- @program_name = name.to_s
41
- end
42
-
43
- #
44
- # Sets the program aliases for the class.
45
- #
46
- # @param [Array] aliases
47
- # The new program aliases.
48
- #
49
- # @example
50
- # alias_program 'vim', 'vi'
51
- #
52
- def alias_program(*aliases)
53
- @program_aliases = aliases.map { |name| name.to_s }
54
- end
55
-
56
- #
57
- # The default path of the program.
58
- #
59
- # @return [String, nil]
60
- # The path to the program.
61
- #
62
- # @since 0.2.0
63
- #
64
- def path
65
- @program_path
66
- end
67
-
68
- #
69
- # Sets the default path to the program.
70
- #
71
- # @param [String] new_path
72
- # The new path to the program.
73
- #
74
- # @return [String, nil]
75
- # The path to the program.
76
- #
77
- # @since 0.2.0
78
- #
79
- def path=(new_path)
80
- @program_path = (File.expand_path(new_path) if new_path)
81
- end
82
- end
83
- end
84
- end
@@ -1,34 +0,0 @@
1
- require 'rprogram/nameable/class_methods'
2
- require 'rprogram/compat'
3
-
4
- module RProgram
5
- module Nameable
6
- def self.included(base)
7
- base.send :extend, ClassMethods
8
- end
9
-
10
- #
11
- # @return [String]
12
- # The program name of the class.
13
- #
14
- def program_name
15
- self.class.program_name
16
- end
17
-
18
- #
19
- # @return [Array]
20
- # The program aliases of the class.
21
- #
22
- def program_aliases
23
- self.class.program_aliases
24
- end
25
-
26
- #
27
- # @return [Array]
28
- # The program names of the class.
29
- #
30
- def program_names
31
- self.class.program_names
32
- end
33
- end
34
- end
@@ -1,2 +0,0 @@
1
- require 'rprogram/options/class_methods'
2
- require 'rprogram/options/options'
@@ -1,112 +0,0 @@
1
- module RProgram
2
- module Options
3
- module ClassMethods
4
- #
5
- # @return [Hash]
6
- # All defined non-options of the class.
7
- #
8
- def non_options
9
- @non_options ||= {}
10
- end
11
-
12
- #
13
- # Searches for the non-option with the matching name in the class
14
- # and it's ancestors.
15
- #
16
- # @param [Symbol, String] name
17
- # The name to search for.
18
- #
19
- # @return [true, false]
20
- # Specifies whether the non-option with the matching name was
21
- # defined.
22
- #
23
- def has_non_option?(name)
24
- name = name.to_sym
25
-
26
- ancestors.each do |base|
27
- if base.include?(RProgram::Options)
28
- return true if base.non_options.include?(name)
29
- end
30
- end
31
-
32
- return false
33
- end
34
-
35
- #
36
- # Searches for the non-option with the matching name in the class
37
- # and it's ancestors.
38
- #
39
- # @param [Symbol, String] name
40
- # The name to search for.
41
- #
42
- # @return [NonOption]
43
- # The non-option with the matching name.
44
- #
45
- def get_non_option(name)
46
- name = name.to_sym
47
-
48
- ancestors.each do |base|
49
- if base.include?(RProgram::Options)
50
- if base.non_options.has_key?(name)
51
- return base.non_options[name]
52
- end
53
- end
54
- end
55
-
56
- return nil
57
- end
58
-
59
- #
60
- # @return [Hash]
61
- # All defined options for the class.
62
- #
63
- def options
64
- @options ||= {}
65
- end
66
-
67
- #
68
- # Searches for the option with the matching name in the class and
69
- # it's ancestors.
70
- #
71
- # @param [Symbol, String] name
72
- # The name to search for.
73
- #
74
- # @return [true, false]
75
- # Specifies whether the option with the matching name was defined.
76
- #
77
- def has_option?(name)
78
- name = name.to_sym
79
-
80
- ancestors.each do |base|
81
- if base.include?(RProgram::Options)
82
- return true if base.options.has_key?(name)
83
- end
84
- end
85
-
86
- return false
87
- end
88
-
89
- #
90
- # Searches for the option with the matching name in the class and
91
- # it's ancestors.
92
- #
93
- # @param [Symbol, String] name
94
- # The name to search for.
95
- #
96
- # @return [Option]
97
- # The option with the matching name.
98
- #
99
- def get_option(name)
100
- name = name.to_sym
101
-
102
- ancestors.each do |base|
103
- if base.include?(RProgram::Options)
104
- return base.options[name] if base.options.has_key?(name)
105
- end
106
- end
107
-
108
- return nil
109
- end
110
- end
111
- end
112
- end
@@ -1,39 +0,0 @@
1
- require 'rprogram/options/class_methods'
2
- require 'rprogram/non_option'
3
- require 'rprogram/option'
4
-
5
- module RProgram
6
- module Options
7
- def self.included(base)
8
- base.send :extend, ClassMethods
9
- end
10
-
11
- #
12
- # @see self.has_non_option?
13
- #
14
- def has_non_option?(name)
15
- self.class.has_non_option?(name)
16
- end
17
-
18
- #
19
- # @see self.get_non_option
20
- #
21
- def get_non_option(name)
22
- self.class.get_non_option(name)
23
- end
24
-
25
- #
26
- # @see self.has_option?
27
- #
28
- def has_option?(name)
29
- self.class.has_option?(name)
30
- end
31
-
32
- #
33
- # @see self.get_option
34
- #
35
- def get_option(name)
36
- self.class.get_option(name)
37
- end
38
- end
39
- end
data/spec/compat_spec.rb DELETED
@@ -1,21 +0,0 @@
1
- require 'rprogram/compat'
2
-
3
- require 'spec_helper'
4
-
5
- describe Compat do
6
- it "should have a list of directories that contain programs" do
7
- Compat.paths.should_not be_empty
8
-
9
- Compat.paths.any? { |dir|
10
- File.directory?(dir)
11
- }.should == true
12
- end
13
-
14
- it "should be able to find programs" do
15
- File.executable?(Compat.find_program('dir')).should == true
16
- end
17
-
18
- it "should be able to find programs by multiple names" do
19
- File.executable?(Compat.find_program_by_names('ls','dir')).should == true
20
- end
21
- end
@@ -1,83 +0,0 @@
1
- require 'rprogram/nameable'
2
-
3
- require 'spec_helper'
4
- require 'classes/named_program'
5
- require 'classes/aliased_program'
6
-
7
- describe Nameable do
8
- describe "named program" do
9
- it "should be able to give a class a program name" do
10
- NamedProgram.program_name.should == 'ls'
11
- end
12
-
13
- it "should not have any program aliases" do
14
- NamedProgram.program_aliases.should be_empty
15
- end
16
-
17
- it "should have one program name" do
18
- NamedProgram.program_names.should == ['ls']
19
- end
20
-
21
- it "should provide an instance method for the program name" do
22
- obj = NamedProgram.new
23
-
24
- obj.program_name.should == 'ls'
25
- end
26
-
27
- it "should provide an instance method for the program names" do
28
- obj = NamedProgram.new
29
-
30
- obj.program_names.should == ['ls']
31
- end
32
- end
33
-
34
- describe "aliased program" do
35
- it "should have program aliases" do
36
- AliasedProgram.program_aliases.should == ['dir']
37
- end
38
-
39
- it "should have one program name" do
40
- AliasedProgram.program_names.should == ['ls', 'dir']
41
- end
42
-
43
- it "should provide an instance method for the program aliases" do
44
- obj = AliasedProgram.new
45
-
46
- obj.program_aliases.should == ['dir']
47
- end
48
-
49
- it "should provide an instance method for the program names" do
50
- obj = AliasedProgram.new
51
-
52
- obj.program_names.should == ['ls', 'dir']
53
- end
54
- end
55
-
56
- describe "path" do
57
- subject { NamedProgram }
58
- after(:all) { NamedProgram.path = nil }
59
-
60
- it "should not have a path by default" do
61
- subject.path.should be_nil
62
- end
63
-
64
- it "should allow setting the path" do
65
- new_path = '/usr/bin/ls'
66
-
67
- subject.path = new_path
68
- subject.path.should == new_path
69
- end
70
-
71
- it "should expand paths" do
72
- subject.path = '/usr/../bin/ls'
73
-
74
- subject.path.should == '/bin/ls'
75
- end
76
-
77
- it "should allow setting the path to nil" do
78
- subject.path = nil
79
-
80
- subject.path.should be_nil
81
- end
82
- end
83
- end