Class: JsRoutes::Configuration
- Inherits:
-
Object
- Object
- JsRoutes::Configuration
- Defined in:
- lib/js_routes/configuration.rb
Constant Summary collapse
- DEFAULTS =
{ namespace: nil, exclude: [], include: //, file: nil, prefix: -> { Rails.application.config.relative_url_root || "" }, url_links: false, camel_case: false, default_url_options: {}, compact: false, serializer: nil, special_options_key: "_options", application: -> { Rails.application }, module_type: 'ESM', documentation: true, }
Instance Method Summary collapse
- #[](attribute) ⇒ Object
- #assign(attributes = nil, &block) ⇒ Object
- #dts? ⇒ Boolean
- #esm? ⇒ Boolean
-
#initialize(attributes = nil) ⇒ Configuration
constructor
A new instance of Configuration.
- #merge(attributes) ⇒ Object
- #modern? ⇒ Boolean
- #output_file ⇒ Object
- #require_esm ⇒ Object
- #source_file ⇒ Object
- #to_hash ⇒ Object
Constructor Details
#initialize(attributes = nil) ⇒ Configuration
Returns a new instance of Configuration.
24 25 26 27 28 |
# File 'lib/js_routes/configuration.rb', line 24 def initialize(attributes = nil) assign(DEFAULTS) return unless attributes assign(attributes) end |
Instance Method Details
#[](attribute) ⇒ Object
45 46 47 |
# File 'lib/js_routes/configuration.rb', line 45 def [](attribute) send(attribute) end |
#assign(attributes = nil, &block) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/js_routes/configuration.rb', line 30 def assign(attributes = nil, &block) if !attributes && !block raise "Provide attributes or block" end tap(&block) if block if attributes attributes.each do |attribute, value| value = value.call if value.is_a?(Proc) send(:"#{attribute}=", value) end end normalize_and_verify self end |
#dts? ⇒ Boolean
61 62 63 |
# File 'lib/js_routes/configuration.rb', line 61 def dts? self.module_type === 'DTS' end |
#esm? ⇒ Boolean
57 58 59 |
# File 'lib/js_routes/configuration.rb', line 57 def esm? module_type === 'ESM' end |
#merge(attributes) ⇒ Object
49 50 51 |
# File 'lib/js_routes/configuration.rb', line 49 def merge(attributes) clone.assign(attributes) end |
#modern? ⇒ Boolean
65 66 67 |
# File 'lib/js_routes/configuration.rb', line 65 def modern? esm? || dts? end |
#output_file ⇒ Object
77 78 79 80 81 82 83 84 |
# File 'lib/js_routes/configuration.rb', line 77 def output_file webpacker_dir = pathname('app', 'javascript') sprockets_dir = pathname('app','assets','javascripts') file_name = file || default_file_name sprockets_file = sprockets_dir.join(file_name) webpacker_file = webpacker_dir.join(file_name) !Dir.exist?(webpacker_dir) && defined?(::Sprockets) ? sprockets_file : webpacker_file end |
#require_esm ⇒ Object
69 70 71 |
# File 'lib/js_routes/configuration.rb', line 69 def require_esm raise "ESM module type is required" unless modern? end |
#source_file ⇒ Object
73 74 75 |
# File 'lib/js_routes/configuration.rb', line 73 def source_file File.dirname(__FILE__) + "/../" + default_file_name end |
#to_hash ⇒ Object
53 54 55 |
# File 'lib/js_routes/configuration.rb', line 53 def to_hash Hash[*members.zip(values).flatten(1)].symbolize_keys end |