Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bbcf86c

Browse files
committed
Clarify config attribute names and overload to_s
Replace Config.config attribute with Config.opts. Config.opts was previously a Hash of valid keys and potential values for config; that role is now played by Config.valid_opts. Also, overload Config.to_s to call Config.opts_string, which returns the valid clojure options string, so that the Compiler can simply interpolate #{Config}, instead of having to call Config.opts_string directly.
1 parent ccafe96 commit bbcf86c

File tree

2 files changed

+22
-17
lines changed

2 files changed

+22
-17
lines changed

lib/clojurescript_rails/compiler.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def self.prepare_ng
1515
end
1616

1717
def compile(file)
18-
`#{@@ng_path} clojure.main #{COMPILER} #{file} #{Config.config_string}`
18+
`#{@@ng_path} clojure.main #{COMPILER} #{file} #{Config}`
1919
end
2020
end
2121
end

lib/clojurescript_rails/config.rb

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,27 @@ module ClojurescriptRails
33
class Config
44

55
class << self
6-
attr_reader :config, :opts
6+
attr_reader :opts, :valid_opts
77
end
88

99
# Valid clojurescript compiler config options
10-
@opts = {
10+
@valid_opts = {
1111
:optimizations => [:simple, :whitespace, :advanced],
1212
:pretty_print => [true, false]
1313
}
1414

15-
# Default configuration
16-
@config = { :optimizations => :advanced }
15+
# Default configuration options
16+
@opts = { :optimizations => :advanced }
1717

1818
##
19-
# config setter
19+
# opts setter
2020
#
2121
# Raises an ArgumentError unless configuration options and values are
22-
# present in Config.opts
22+
# present in Config.valid_opts
2323

24-
def self.config=(config)
25-
invalid = config.reject do |k, v|
26-
@opts.has_key?(k) and @opts[k].include?(v)
24+
def self.opts=(opts)
25+
invalid = opts.reject do |k, v|
26+
@valid_opts.has_key?(k) and @valid_opts[k].include?(v)
2727
end
2828

2929
unless invalid.empty?
@@ -32,29 +32,34 @@ def self.config=(config)
3232
raise ArgumentError.new(msg)
3333
end
3434

35-
@config = config
35+
@opts = opts
3636
end
3737

38+
def self.to_s
39+
opts_string
40+
end
41+
42+
private
43+
3844
##
39-
# Returns the clojure map string representation of @config
45+
# Returns the clojure map string representation of @opts
4046

41-
def self.config_string
42-
kvs = config_to_clj().reduce("") { |s, kv| "#{s} #{kv[0]} #{kv[1]}" }
47+
def self.opts_string
48+
kvs = opts_to_clj().reduce("") { |s, kv| "#{s} #{kv[0]} #{kv[1]}" }
4349
"\"{#{kvs} }\""
4450
end
4551

4652
##
4753
# Returns a Hash with keys and values converted to strings represented
4854
# as clojure literals
4955

50-
def self.config_to_clj
51-
@config.reduce({}) do |coll, kv|
56+
def self.opts_to_clj
57+
@opts.reduce({}) do |coll, kv|
5258
k, v = kv.map { |x| item_to_clj x }
5359
coll.merge k => v
5460
end
5561
end
5662

57-
private
5863
def self.item_to_clj(item)
5964
item.inspect.gsub /_/, "-"
6065
end

0 commit comments

Comments
 (0)