Module: Cockpit::ClassMethods

Defined in:
lib/cockpit/core/include.rb

Instance Method Summary collapse

Instance Method Details

#cockpit(options = {}, &block) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/cockpit/core/include.rb', line 9

def cockpit(options = {}, &block)
  if block_given?
    options = {:store => options.to_sym} unless options.is_a?(Hash)
    @cockpit = Cockpit::Settings.define!(options.merge(:for => self), &block)
    
    @cockpit.roots.map(&:key).flatten.each do |key|
      define_method key do
        send(:cockpit).send(key)
      end
      
      define_method "#{key}=" do |value|
        send(:cockpit).send("#{key}=", value)
      end
      
      define_method "#{key}?" do
        send(:cockpit).present?(key)
      end
      
      define_method "setting" do |key, scope|
        Cockpit::Settings.for(scope ? scope.to_s.camelize : NilClass)[key]
      end
    end
  end
  
  @cockpit
end

#key(*args) ⇒ Object



37
38
39
# File 'lib/cockpit/core/include.rb', line 37

def key(*args)
  
end