Class: Wedge::Config

Inherits:
Object show all
Includes:
Methods
Defined in:
lib/wedge/config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Methods

#client?, included, #server?

Constructor Details

#initialize(opts = {}) ⇒ Config

Setup initial opts values

Parameters:

  • opts (Hash) (defaults to: {})

    The initial params for #opts.



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
42
43
44
# 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,
    assets_headers: {},
    gzip_assets: false,
    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: [],
    opal: {},
    allowed_client_data: %w(debug 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



100
101
102
103
104
105
106
# File 'lib/wedge/config.rb', line 100

def method_missing(method, *args, &block)
  if @data.respond_to?(method, true)
    @data.send method, *args, &block
  else
    super
  end
end

Instance Attribute Details

#dataOpenStruct

Stores the options for the config

Returns:

  • (OpenStruct)


8
9
10
# File 'lib/wedge/config.rb', line 8

def data
  @data
end

Instance Method Details

#client_dataObject



46
47
48
# File 'lib/wedge/config.rb', line 46

def client_data
  @data.dup.select {|k, v| allowed_client_data.include? k }
end

#plugin(name, settings = {}, &block) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/wedge/config.rb', line 50

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)

    if defined? klass::ServerMethods
      if server?
        Wedge::Component.send(:include, klass::ServerMethods)
        Wedge::Component.extend(klass::ServerMethods)
      end

      Wedge::Component.wedge_on_server klass::ServerMethods
    end
  end
end

#plugins=(plugins) ⇒ Object



84
85
86
# File 'lib/wedge/config.rb', line 84

def plugins= plugins
  plugins.each { |p| plugin(p.to_s) }
end

#scope=(value) ⇒ Object



88
89
90
91
92
93
94
95
96
97
98
# File 'lib/wedge/config.rb', line 88

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