GitHub Sale: sign up for any paid plan this week and pay nothing until January 1, 2009!  [ hide ]

public
Fork of halorgium/mephisto
Description: A mirror of the mephisto code-base
Homepage: http://mephistoblog.com/
Clone URL: git://github.com/zmack/mephisto.git
svenfuchs (author)
Wed Feb 20 11:11:20 -0800 2008
commit  1ad1b56b4a6c9284534b0afbb9d5d87715ae4312
tree    adc435b61f05728a991fd314188bc3e75cfb6038
parent  2772ec18227b04b3cb618748a2900a7b93b84d94
mephisto / vendor / plugins / engines_config / lib / engines / configurable.rb
100644 57 lines (46 sloc) 1.273 kb
1
2
3
4
5
6
7
8
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
module Engines
  class Plugin
    module Configurable
      class Config < ActiveRecord::Base
        set_table_name 'plugin_configs'
        serialize :options, Hash
    
        def after_initialize
          write_attribute(:options, {}) if read_attribute(:options).nil?
        end
      end
 
      def option(property, default, field_type = :text_field)
        instance_eval <<-END, __FILE__, __LINE__
def #{property}
config.options[#{property.inspect}] || #{default.inspect}
end
def #{property}=(value)
config.options[#{property.inspect}] = value
end
END
        default_options[property] = field_type
      end
  
      def options=(options)
        config.options = options
      end
  
      def default_options
        @default_options ||= {}
      end
      
      def save!
        config.save!
      end
      
      def destroy
        config.destroy
        @config = nil
      end
      
      private
  
      def config
        @config ||= Config.find_or_initialize_by_name(conf_name)
      end
      
      # allow subclasses to hook in here
      def conf_name
        name
      end
    end
  end
end
 
Engines::Plugin.send :include, Engines::Plugin::Configurable