ruby-elm 0.5.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ab58c13391e7b12c8e4517b88a192398bb5813d5
4
+ data.tar.gz: 9adb70255ee68c87361efc69ab42f187c476d1f6
5
+ SHA512:
6
+ metadata.gz: 00f8481b954473056f9ecee4130e81176a638108dd68727775804a312112e3f61c880cdcb030380f67a4b09424c47720f3e733e62d6e5b814b8f1ea023210ad2
7
+ data.tar.gz: 77c6843cf8f147b1297a0f03837c65ce4c0ad7eed5aecffa6e4afd42e666b68013e3bf4c14077e30798474571da76bde7b5df8876f585a1d4cff975ce91a75f2
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'elm'
4
+ require 'elm/bin'
5
+
6
+ exit Elm::Bin.exec ARGV
@@ -0,0 +1,23 @@
1
+ require 'contracts'
2
+ require 'elm/runnable'
3
+ require 'elm/files'
4
+ require 'elm/compiler'
5
+ require 'elm/opt_parser'
6
+ require 'elm/options'
7
+ require 'elm/bin'
8
+
9
+ # Elm ruby wrapper
10
+ module Elm
11
+ include Contracts::Core
12
+ include Contracts::Builtin
13
+
14
+ Contract None => Elm::Runnable
15
+ def self.make
16
+ Elm::Runnable.new 'elm-make'
17
+ end
18
+
19
+ Contract None => Elm::Compiler
20
+ def self.compiler
21
+ Elm::Compiler.with make
22
+ end
23
+ end
@@ -0,0 +1,29 @@
1
+ require 'contracts'
2
+ require 'elm'
3
+
4
+ module Elm
5
+ # Executable to be used in CLI
6
+ class Bin
7
+ include Contracts::Core
8
+ include Contracts::Builtin
9
+
10
+ # rubocop:disable Metrics/MethodLength
11
+ Contract ArrayOf[String] => Bool
12
+ def self.exec(argv)
13
+ options = Elm::OptParser.parse argv
14
+ begin
15
+ compile_output = Elm.compiler.files(argv, with_options: options).to_file
16
+ rescue ExecutableNotFoundError => executable_not_found
17
+ $stderr.puts executable_not_found.message
18
+ exit false
19
+ rescue CompilerError => compiler_error
20
+ $stderr.puts compiler_error.message
21
+ exit false
22
+ end
23
+ $stderr.puts compile_output.stderr
24
+ puts compile_output.stdout
25
+ true
26
+ end
27
+ # rubocop:enable Metrics/MethodLength
28
+ end
29
+ end
@@ -0,0 +1,41 @@
1
+ require 'contracts'
2
+ require 'elm/runnable'
3
+ require 'elm/files'
4
+
5
+ module Elm
6
+ # Compile a set of elm files with options
7
+ class Compiler
8
+ include Contracts::Core
9
+ include Contracts::Builtin
10
+
11
+ Contract Runnable => Compiler
12
+ def self.with(runnable)
13
+ Compiler.new runnable
14
+ end
15
+
16
+ Contract ArrayOf[String], KeywordArgs[with_options: Optional[Elm::Options]] => Files # rubocop:disable Metrics/LineLength
17
+ def files(files_list, with_options: Elm::Options.new)
18
+ Files.new @make, files_list, with_options
19
+ end
20
+
21
+ # rubocop:disable Lint/DuplicateMethods
22
+ Contract ArrayOf[String], KeywordArgs[with_options: { output: Maybe[String],
23
+ yes: Maybe[Bool],
24
+ report: Maybe[Symbol],
25
+ warn: Maybe[Bool],
26
+ docs: Maybe[String] }] => Files # rubocop:disable Metrics/LineLength
27
+ def files(files_list, with_options: {})
28
+ files files_list, with_options: Elm::Options.with(with_options)
29
+ end
30
+ # rubocop:enable Lint/DuplicateMethods
31
+
32
+ private
33
+
34
+ Contract Elm::Runnable => Elm::Compiler
35
+ def initialize(runnable)
36
+ @make = runnable
37
+
38
+ self
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,84 @@
1
+ require 'contracts'
2
+ require 'tempfile'
3
+ require 'elm/runnable'
4
+ require 'elm/options'
5
+
6
+ module Elm
7
+ # Error raised if run fail
8
+ class CompilerError < RuntimeError
9
+ end
10
+
11
+ # Compilation output including status
12
+ class CompileOutput
13
+ include Contracts::Core
14
+ include Contracts::Builtin
15
+
16
+ attr_reader :output, :run_status
17
+
18
+ Contract String, RunSuccess => CompileOutput
19
+ def initialize(output, run_status)
20
+ @output = output
21
+ @run_status = run_status
22
+
23
+ self
24
+ end
25
+
26
+ Contract None => String
27
+ def stdout
28
+ @run_status.stdout
29
+ end
30
+
31
+ Contract None => String
32
+ def stderr
33
+ @run_status.stderr
34
+ end
35
+ end
36
+
37
+ # Elm files to be compiled
38
+ class Files
39
+ include Contracts::Core
40
+ include Contracts::Builtin
41
+
42
+ Contract Elm::Runnable, ArrayOf[String], Elm::Options => Elm::Files
43
+ def initialize(make, files, options)
44
+ @make = make
45
+ @files = files
46
+ @options = options.with_yes
47
+
48
+ self
49
+ end
50
+
51
+ Contract None => CompileOutput
52
+ def to_s
53
+ content = ''
54
+ run_status = nil
55
+ Tempfile.open(['elm', '.js']) do |tempfile|
56
+ run_status = compile @options.with_output(tempfile.path)
57
+ content = File.read tempfile
58
+ end
59
+ CompileOutput.new content, run_status
60
+ end
61
+
62
+ Contract None => CompileOutput
63
+ def to_file
64
+ run_status = compile
65
+ CompileOutput.new @options.output, run_status
66
+ end
67
+
68
+ private
69
+
70
+ Contract None => RunSuccess
71
+ def compile
72
+ compile @options
73
+ end
74
+
75
+ # rubocop:disable Lint/DuplicateMethods
76
+ Contract Elm::Options => RunSuccess
77
+ def compile(options)
78
+ status = @make.run(@files + options.to_a)
79
+ raise(CompilerError, status.stderr) if status.is_a? RunError
80
+ status
81
+ end
82
+ # rubocop:enable Lint/DuplicateMethods
83
+ end
84
+ end
@@ -0,0 +1,64 @@
1
+ require 'contracts'
2
+ require 'optparse'
3
+ require 'elm/options'
4
+
5
+ module Elm
6
+ # Parse command line options
7
+ class OptParser
8
+ include Contracts::Core
9
+ include Contracts::Builtin
10
+
11
+ # rubocop:disable Metrics/AbcSize
12
+ # rubocop:disable Metrics/MethodLength
13
+ Contract ArrayOf[String] => Options
14
+ def self.parse(args)
15
+ options = Options.new
16
+
17
+ opt_parser = OptionParser.new do |opts|
18
+ opts.banner = 'Usage: ruby-elm [FILES...] ' \
19
+ '[--output FILE] [--yes] [--report FORMAT] [--warn] [--docs FILE]'
20
+
21
+ opts.separator ''
22
+ opts.separator 'Available options:'
23
+
24
+ opts.on_tail('-h', '--help',
25
+ 'Show this help text') do
26
+ puts opts
27
+ exit
28
+ end
29
+
30
+ opts.on('--output [FILE]',
31
+ 'Write result to the given .html or .js FILE.') do |output|
32
+ options.output = output
33
+ end
34
+
35
+ opts.on('--yes',
36
+ 'Reply \'yes\' to all automated prompts.') do
37
+ options.yes = true
38
+ end
39
+
40
+ opts.on('--report [FORMAT]', [:normal, :json],
41
+ 'Format of error and warning reports',
42
+ ' (normal or json)') do |format|
43
+ options.report = format
44
+ end
45
+
46
+ opts.on('--warn',
47
+ 'Report warnings to improve code quality.') do
48
+ options.warn = true
49
+ end
50
+
51
+ opts.on('--docs [FILE]',
52
+ 'Write documentation to FILE as JSON.') do |doc|
53
+ options.docs = doc
54
+ end
55
+
56
+ opts.separator ''
57
+ opts.separator 'Examples:'
58
+ end
59
+
60
+ opt_parser.parse! args
61
+ options
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,158 @@
1
+ require 'contracts'
2
+
3
+ module Elm
4
+ # rubocop:disable Metrics/ClassLength
5
+ # Error raised when trying to set a bad report format
6
+ class BadReportFormatError < RuntimeError
7
+ end
8
+
9
+ # Options to run elm
10
+ class Options
11
+ include Contracts::Core
12
+ include Contracts::Builtin
13
+
14
+ Contract KeywordArgs[output: Optional[String],
15
+ yes: Optional[Bool],
16
+ report: Optional[Symbol],
17
+ warn: Optional[Bool],
18
+ docs: Optional[Maybe[String]]] => Options
19
+ def self.with(output: 'index.html', yes: false, report: :normal,
20
+ warn: false, docs: nil)
21
+ opts = Options.new
22
+ opts.output = output
23
+ opts.yes = yes
24
+ opts.report = report
25
+ opts.warn = warn
26
+ opts.docs = docs unless docs.nil?
27
+ opts
28
+ end
29
+
30
+ Contract Options => Options
31
+ def self.clone(opts)
32
+ Options.with(output: opts.output,
33
+ yes: opts.yes,
34
+ report: opts.report,
35
+ warn: opts.warn,
36
+ docs: opts.docs)
37
+ end
38
+
39
+ FORMATS = [:normal, :json].freeze
40
+
41
+ attr_reader :output, :yes, :report, :warn, :docs
42
+
43
+ Contract None => Options
44
+ def initialize
45
+ @output = 'index.html'
46
+ @yes = false
47
+ @report = :normal
48
+ @warn = false
49
+ @docs = nil
50
+
51
+ self
52
+ end
53
+
54
+ # rubocop:disable Style/TrivialAccessors
55
+ Contract String => String
56
+ def output=(value)
57
+ # check output is valid
58
+ @output = value
59
+ end
60
+
61
+ Contract Bool => Bool
62
+ def yes=(value)
63
+ @yes = value
64
+ end
65
+
66
+ Contract Symbol => Symbol
67
+ def report=(value)
68
+ if FORMATS.index(value).nil?
69
+ raise BadReportFormatError, "'#{value}' is not a valid report format"
70
+ end
71
+ @report = value
72
+ end
73
+
74
+ Contract Bool => Bool
75
+ def warn=(value)
76
+ @warn = value
77
+ end
78
+
79
+ Contract String => String
80
+ def docs=(value)
81
+ @docs = value
82
+ end
83
+ # rubocop:enable Style/TrivialAccessors
84
+
85
+ Contract None => ArrayOf[String]
86
+ def to_a
87
+ res = []
88
+ push_output res
89
+ push_yes res
90
+ push_report res
91
+ push_warn res
92
+ push_docs res
93
+ res
94
+ end
95
+
96
+ Contract String => Options
97
+ def with_output(output)
98
+ opts = Options.clone self
99
+ opts.output = output
100
+ opts
101
+ end
102
+
103
+ Contract None => Options
104
+ def with_yes
105
+ opts = Options.clone self
106
+ opts.yes = true
107
+ opts
108
+ end
109
+
110
+ Contract Symbol => Options
111
+ def with_report(report)
112
+ opts = Options.clone self
113
+ opts.report = report
114
+ opts
115
+ end
116
+
117
+ Contract None => Options
118
+ def with_warn
119
+ opts = Options.clone self
120
+ opts.warn = true
121
+ opts
122
+ end
123
+
124
+ Contract String => Options
125
+ def with_docs(docs)
126
+ opts = Options.clone self
127
+ opts.docs = docs
128
+ opts
129
+ end
130
+
131
+ private
132
+
133
+ Contract ArrayOf[String] => Maybe[ArrayOf[String]]
134
+ def push_output(res)
135
+ res << '--output' && res << @output unless @output == 'index.html'
136
+ end
137
+
138
+ Contract ArrayOf[String] => Maybe[ArrayOf[String]]
139
+ def push_yes(res)
140
+ res << '--yes' if @yes
141
+ end
142
+
143
+ Contract ArrayOf[String] => Maybe[ArrayOf[String]]
144
+ def push_report(res)
145
+ res << '--report' && res << @report.to_s unless @report == :normal
146
+ end
147
+
148
+ Contract ArrayOf[String] => Maybe[ArrayOf[String]]
149
+ def push_warn(res)
150
+ res << '--warn' if @warn
151
+ end
152
+
153
+ Contract ArrayOf[String] => Maybe[ArrayOf[String]]
154
+ def push_docs(res)
155
+ res << '--docs' && res << @docs unless @docs.nil?
156
+ end
157
+ end
158
+ end
@@ -0,0 +1,81 @@
1
+ require 'contracts'
2
+ require 'mkmf'
3
+ require 'open3'
4
+
5
+ module Elm
6
+ # Error raised if executable not found
7
+ class ExecutableNotFoundError < RuntimeError
8
+ end
9
+
10
+ # Status if execution of Runnable
11
+ class RunStatus
12
+ include Contracts::Core
13
+ include Contracts::Builtin
14
+
15
+ attr_reader :stdout, :stderr
16
+
17
+ Contract String, KeywordArgs[with_error: Optional[String]] => RunStatus
18
+ def initialize(stdout, with_error: '')
19
+ @stdout = stdout
20
+ @stderr = with_error
21
+
22
+ self
23
+ end
24
+ end
25
+
26
+ # Status when execution is successful
27
+ class RunSuccess < RunStatus
28
+ end
29
+
30
+ # Status when execution fail
31
+ class RunError < RunStatus
32
+ end
33
+
34
+ # Run command
35
+ class Runnable
36
+ include Contracts::Core
37
+ include Contracts::Builtin
38
+
39
+ RunStatus = Or[RunSuccess, RunError]
40
+
41
+ Contract String => Runnable
42
+ def initialize(command)
43
+ @command = command
44
+
45
+ unless exists?
46
+ raise ExecutableNotFoundError,
47
+ "Please install executable '#{@command}'"
48
+ end
49
+
50
+ self
51
+ end
52
+
53
+ Contract None => RunStatus
54
+ def run
55
+ run []
56
+ end
57
+
58
+ # rubocop:disable Lint/DuplicateMethods
59
+ Contract ArrayOf[String] => RunStatus
60
+ def run(options)
61
+ cmd = [@command] + options
62
+ Open3.popen3(*cmd) do |_i, o, e, t|
63
+ out = o.read || ''
64
+ err = e.read || ''
65
+ if t.value.success?
66
+ RunSuccess.new out, with_error: err
67
+ else
68
+ RunError.new out, with_error: err
69
+ end
70
+ end
71
+ end
72
+ # rubocop:enable Lint/DuplicateMethods
73
+
74
+ private
75
+
76
+ Contract None => Bool
77
+ def exists?
78
+ !find_executable0(@command).nil?
79
+ end
80
+ end
81
+ end
metadata ADDED
@@ -0,0 +1,208 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruby-elm
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.0
5
+ platform: ruby
6
+ authors:
7
+ - Yves Brissaud
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-03-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.3'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 3.3.0
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '3.3'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 3.3.0
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.13'
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: 2.13.0
43
+ type: :development
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '2.13'
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 2.13.0
53
+ - !ruby/object:Gem::Dependency
54
+ name: guard-rspec
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - "~>"
58
+ - !ruby/object:Gem::Version
59
+ version: '4.6'
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: 4.6.4
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '4.6'
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: 4.6.4
73
+ - !ruby/object:Gem::Dependency
74
+ name: simplecov
75
+ requirement: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - "~>"
78
+ - !ruby/object:Gem::Version
79
+ version: '0.10'
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: 0.10.0
83
+ type: :development
84
+ prerelease: false
85
+ version_requirements: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.10'
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: 0.10.0
93
+ - !ruby/object:Gem::Dependency
94
+ name: cucumber
95
+ requirement: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - "~>"
98
+ - !ruby/object:Gem::Version
99
+ version: '2.3'
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: 2.3.2
103
+ type: :development
104
+ prerelease: false
105
+ version_requirements: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - "~>"
108
+ - !ruby/object:Gem::Version
109
+ version: '2.3'
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: 2.3.2
113
+ - !ruby/object:Gem::Dependency
114
+ name: guard-cucumber
115
+ requirement: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - "~>"
118
+ - !ruby/object:Gem::Version
119
+ version: '2.0'
120
+ type: :development
121
+ prerelease: false
122
+ version_requirements: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - "~>"
125
+ - !ruby/object:Gem::Version
126
+ version: '2.0'
127
+ - !ruby/object:Gem::Dependency
128
+ name: rake
129
+ requirement: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - "~>"
132
+ - !ruby/object:Gem::Version
133
+ version: '10.5'
134
+ type: :development
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - "~>"
139
+ - !ruby/object:Gem::Version
140
+ version: '10.5'
141
+ - !ruby/object:Gem::Dependency
142
+ name: rubocop
143
+ requirement: !ruby/object:Gem::Requirement
144
+ requirements:
145
+ - - "~>"
146
+ - !ruby/object:Gem::Version
147
+ version: '0.37'
148
+ type: :development
149
+ prerelease: false
150
+ version_requirements: !ruby/object:Gem::Requirement
151
+ requirements:
152
+ - - "~>"
153
+ - !ruby/object:Gem::Version
154
+ version: '0.37'
155
+ - !ruby/object:Gem::Dependency
156
+ name: contracts
157
+ requirement: !ruby/object:Gem::Requirement
158
+ requirements:
159
+ - - "~>"
160
+ - !ruby/object:Gem::Version
161
+ version: 0.13.0
162
+ type: :runtime
163
+ prerelease: false
164
+ version_requirements: !ruby/object:Gem::Requirement
165
+ requirements:
166
+ - - "~>"
167
+ - !ruby/object:Gem::Version
168
+ version: 0.13.0
169
+ description: Executable and ruby library to compiler elm files.
170
+ email: yves.brissaud@gmail.com
171
+ executables:
172
+ - ruby-elm-make
173
+ extensions: []
174
+ extra_rdoc_files: []
175
+ files:
176
+ - bin/ruby-elm-make
177
+ - lib/elm.rb
178
+ - lib/elm/bin.rb
179
+ - lib/elm/compiler.rb
180
+ - lib/elm/files.rb
181
+ - lib/elm/opt_parser.rb
182
+ - lib/elm/options.rb
183
+ - lib/elm/runnable.rb
184
+ homepage: https://github.com/eunomie/ruby-elm
185
+ licenses:
186
+ - MIT
187
+ metadata: {}
188
+ post_install_message:
189
+ rdoc_options: []
190
+ require_paths:
191
+ - lib
192
+ required_ruby_version: !ruby/object:Gem::Requirement
193
+ requirements:
194
+ - - ">="
195
+ - !ruby/object:Gem::Version
196
+ version: '0'
197
+ required_rubygems_version: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - ">="
200
+ - !ruby/object:Gem::Version
201
+ version: '0'
202
+ requirements: []
203
+ rubyforge_project:
204
+ rubygems_version: 2.5.1
205
+ signing_key:
206
+ specification_version: 4
207
+ summary: Elm ruby wrapper
208
+ test_files: []