guard-ragel 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/README.md +10 -1
  2. data/lib/guard/ragel.rb +44 -24
  3. metadata +40 -10
data/README.md CHANGED
@@ -34,11 +34,20 @@ Defaults to writing to the same directory in the ruby output format.
34
34
 
35
35
  An input file of ragel.rl will output a file of ragel.rb in the same directory.
36
36
 
37
+ The output format can be inferred from the input filename if it has multiple
38
+ extensions, e.g:
39
+
40
+ example.rb.rl
41
+
42
+ will generate
43
+
44
+ example.rb
37
45
 
38
46
  ## Options
39
47
 
40
48
  ```ruby
41
- :output_format => :ruby # The output format to generate, this defaults to :ruby but supports one of:
49
+ :output_format => :ruby # The default output format to generate, if
50
+ # one cannot be determined from the filename
42
51
  #
43
52
  # :c The host language is C, C++, Obj-C or Obj-C++
44
53
  # :d The host language is D
@@ -7,20 +7,31 @@ module Guard
7
7
 
8
8
  RagelError = Class.new(RuntimeError)
9
9
 
10
- OUTPUT_FORMATS = {
11
- :c => ['-C', 'c'],
12
- :d => ['-D', 'd'],
13
- :go => ['Z', 'go'],
14
- :java => ['J', 'java'],
15
- :ruby => ['-R', 'rb'],
16
- :csharp => ['-A', 'cs'],
17
- :ocaml => ['-O', 'caml'],
10
+ EXTENSIONS = {
11
+ :c => 'c',
12
+ :d => 'd',
13
+ :go => 'go',
14
+ :java => 'java',
15
+ :ruby => 'rb',
16
+ :csharp => 'cs',
17
+ :ocaml => 'caml',
18
+ }
19
+ FORMAT_FLAGS = {
20
+ 'c' => '-C',
21
+ 'd' => '-D',
22
+ 'go' => '-Z',
23
+ 'java' => '-J',
24
+ 'rb' => '-R',
25
+ 'cs' => '-A',
26
+ 'caml' => '-O'
18
27
  }
19
28
 
20
29
  DEFAULTS = {
21
- :output_format => :ruby, # Output format of ragel
30
+ :output_format => :ruby, # Output format to use if it cannot be
31
+ # determined from the original filename
22
32
  :options => '', # Options to pass to ragel
23
33
  :notification => true, # Enable notifications?
34
+ :extension => nil, # Override output extension
24
35
  }
25
36
 
26
37
  def initialize(watchers = [], options = {})
@@ -33,14 +44,21 @@ module Guard
33
44
  # @return [String] filename generated by running ragel
34
45
  #
35
46
  def build_ragel(file)
36
- # Determine name of the output file
37
- filename = File.basename(file, File.extname(file))
38
47
  output_dir = options[:output] || File.dir(file)
39
- output_extension = options[:extension] || format_options[1]
40
- output_file = File.join(output_dir, "#{filename}.#{output_extension}")
48
+
49
+ filename, extension = output_filename(file)
50
+ format_type = options[:output_format]
51
+ extension ||= EXTENSIONS[format_type]
52
+ if extension.nil?
53
+ raise ArgumentError, "Unable to determine output format from #{filename} with default output #{format_type}"
54
+ end
55
+ format_flag = FORMAT_FLAGS[extension]
41
56
 
42
- # Flag to make the chosen format
43
- format_flag = format_options[0]
57
+ if override_extension = options[:extension]
58
+ extension = override_extension
59
+ end
60
+
61
+ output_file = File.join(output_dir, "#{filename}.#{extension}")
44
62
 
45
63
  result = system "ragel #{options[:options]} #{format_flag} #{file} -o #{output_file}"
46
64
  raise RagelError, $? unless result
@@ -59,16 +77,16 @@ module Guard
59
77
 
60
78
  begin
61
79
  output_file = build_ragel(file)
62
- message = "Generated '#{output_file}' from '#{file}'"
63
- ::Guard::UI.info "Guard::Ragel #{message}", :reset => true
80
+ message = "generated '#{output_file}' from '#{file}'"
81
+ ::Guard::UI.info "Guard::Ragel -> #{message}", :reset => true
64
82
  if options[:notification]
65
83
  ::Guard::Notifier.notify(message, :title => "Guard::Ragel", :image => :success)
66
84
  end
67
85
  output_file
68
86
 
69
87
  rescue RagelError => error
70
- message = "Failed to generate '#{output_file}' from '#{file}', error #{error.message}"
71
- ::Guard::UI.error "Guard::Ragel #{message}"
88
+ message = "failed to generate '#{output_file}' from '#{file}', error #{error.message}"
89
+ ::Guard::UI.error "Guard::Ragel -> #{message}"
72
90
  if options[:notification]
73
91
  ::Guard::Notifier.notify(message, :title => "Guard::Ragel", :image => :error)
74
92
  end
@@ -90,12 +108,14 @@ module Guard
90
108
 
91
109
  private #####################################################################
92
110
 
93
- def format_options
94
- format_type = options[:output_format]
95
- unless OUTPUT_FORMATS.key?(format_type)
96
- raise ArgumentError, "Unknown output format #{format_type}"
111
+ def output_filename(input_filename)
112
+ basename = File.basename(input_filename, File.extname(input_filename))
113
+ extension = File.extname(basename)
114
+
115
+ if extension[0, 1].eql?('.')
116
+ return [File.basename(basename, extension), extension.slice(1..-1)]
97
117
  end
98
- OUTPUT_FORMATS[format_type]
118
+ [basename]
99
119
  end
100
120
 
101
121
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: guard-ragel
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
5
- prerelease:
4
+ hash: 23
5
+ prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 3
10
- version: 0.0.3
9
+ - 4
10
+ version: 0.0.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - John Barker
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-06-29 00:00:00 +08:00
18
+ date: 2011-07-05 00:00:00 +08:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -51,9 +51,25 @@ dependencies:
51
51
  type: :development
52
52
  version_requirements: *id002
53
53
  - !ruby/object:Gem::Dependency
54
- name: rspec
54
+ name: rake
55
55
  prerelease: false
56
56
  requirement: &id003 !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ hash: 63
62
+ segments:
63
+ - 0
64
+ - 9
65
+ - 2
66
+ version: 0.9.2
67
+ type: :development
68
+ version_requirements: *id003
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ prerelease: false
72
+ requirement: &id004 !ruby/object:Gem::Requirement
57
73
  none: false
58
74
  requirements:
59
75
  - - ">"
@@ -66,11 +82,25 @@ dependencies:
66
82
  - rc
67
83
  version: 2.0.0.rc
68
84
  type: :development
69
- version_requirements: *id003
85
+ version_requirements: *id004
86
+ - !ruby/object:Gem::Dependency
87
+ name: rdoc
88
+ prerelease: false
89
+ requirement: &id005 !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ hash: 3
95
+ segments:
96
+ - 0
97
+ version: "0"
98
+ type: :development
99
+ version_requirements: *id005
70
100
  - !ruby/object:Gem::Dependency
71
101
  name: guard-rspec
72
102
  prerelease: false
73
- requirement: &id004 !ruby/object:Gem::Requirement
103
+ requirement: &id006 !ruby/object:Gem::Requirement
74
104
  none: false
75
105
  requirements:
76
106
  - - ">="
@@ -80,7 +110,7 @@ dependencies:
80
110
  - 0
81
111
  version: "0"
82
112
  type: :development
83
- version_requirements: *id004
113
+ version_requirements: *id006
84
114
  description: Guard::Ragel automatically rebuilds ragel .rl files into their corresponding .rb files
85
115
  email:
86
116
  - jebarker@gmail.com
@@ -127,7 +157,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
127
157
  requirements: []
128
158
 
129
159
  rubyforge_project:
130
- rubygems_version: 1.6.2
160
+ rubygems_version: 1.3.7
131
161
  signing_key:
132
162
  specification_version: 3
133
163
  summary: Guard gem for Ragel