Class: Wedge::Config
Instance Attribute Summary collapse
-
#data ⇒ OpenStruct
Stores the options for the config.
Instance Method Summary collapse
- #client_data ⇒ Object
-
#initialize(opts = {}) ⇒ Config
constructor
Setup initial opts values.
- #method_missing(method, *args, &block) ⇒ Object
- #plugin(name, settings = {}, &block) ⇒ Object
- #plugins=(plugins) ⇒ Object
- #scope=(value) ⇒ Object
Methods included from Methods
Constructor Details
#initialize(opts = {}) ⇒ Config
Setup initial opts values
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/wedge/config.rb', line 13 def initialize(opts = {}) @data = HashObject.new({ name: nil, path: nil, html: nil, scope: nil, block: nil, debug: false, app_dir: 'app', assets_url: '/assets/wedge', assets_key: nil, cache_assets: false, is_plugin: false, compile_str: false, skip_call_middleware: false, requires: IndifferentHash.new, triggered_browser_events: false, store: IndifferentHash.new, settings: IndifferentHash.new, tmpl: IndifferentHash.new, on_block: [], on_compile: [], on_block_count: 0, server_methods: [], initialize_args: [], plugins: [], allowed_client_data: %w(name path method_args method_called store tmpl key cache_assets assets_key assets_url assets_url_with_host) }.merge(opts)) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
88 89 90 91 92 93 94 |
# File 'lib/wedge/config.rb', line 88 def method_missing(method, *args, &block) if @data.respond_to?(method, true) @data.send method, *args, &block else super end end |
Instance Attribute Details
#data ⇒ OpenStruct
Stores the options for the config
8 9 10 |
# File 'lib/wedge/config.rb', line 8 def data @data end |
Instance Method Details
#client_data ⇒ Object
43 44 45 |
# File 'lib/wedge/config.rb', line 43 def client_data @data.dup.select {|k, v| allowed_client_data.include? k } end |
#plugin(name, settings = {}, &block) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/wedge/config.rb', line 47 def plugin(name, settings = {}, &block) plugin_name = "#{name}_plugin" Wedge.config.settings[plugin_name] = settings unless RUBY_ENGINE == 'opal' require "wedge/plugins/#{name}" end klass = Wedge.config.component_class[plugin_name] unless plugins.include? klass.config.path klass.config.settings = settings klass.config.block = block klass.config.is_plugin = true plugins << klass.config.path plugins.uniq! # Merge in instance/class methods Wedge::Component.send(:include, klass::InstanceMethods) if defined?(klass::InstanceMethods) Wedge::Component.extend(klass::ClassMethods) if defined?(klass::ClassMethods) end end |
#plugins=(plugins) ⇒ Object
72 73 74 |
# File 'lib/wedge/config.rb', line 72 def plugins= plugins plugins.each { |p| plugin(p.to_s) } end |
#scope=(value) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/wedge/config.rb', line 76 def scope= value if value.respond_to? :new begin @data.scope = value.new rescue @data.scope = value.new({}) end else @data.scope = value end end |