Class: Mashfeed::Plugin::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/mashfeed/plugin.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ Base

preset default options



36
37
38
39
40
# File 'lib/mashfeed/plugin.rb', line 36

def initialize(params={})
  @params = {}
  self.class.options.each_pair{|k, v| @params[k] = v[:default] }
  params.each_pair{|k, v| @params[k.to_s] = v }
end

Class Method Details

.inheritable_accessor(*syms) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/mashfeed/plugin.rb', line 6

def self.inheritable_accessor(*syms)
  syms.each do |sym|
    class_eval <<-__EOM__
      def self.#{sym}(#{sym}=nil)
        #{sym}.nil? ? read_inheritable_attribute(:#{sym}) : write_inheritable_attribute(:#{sym}, #{sym})
      end
      def self.#{sym}=(#{sym})
        write_inheritable_attribute(:#{sym}, #{sym})
      end
    __EOM__
  end
end

.option(name, options = {}) ⇒ Object

set plugin’s option



22
23
24
25
26
27
28
# File 'lib/mashfeed/plugin.rb', line 22

def self.option(name, options={})
  write_inheritable_attribute(:options, self.options.merge(name.to_s => options))
  class_eval <<-__EOM__
    def #{name}(val=nil); val.nil? ? @params["#{name}"] : @params["#{name}"]=val ;end
    def #{name}=(val); @params["#{name}"] = val;end
  __EOM__
end

.optionsObject

get this plugin options



31
32
33
# File 'lib/mashfeed/plugin.rb', line 31

def self.options
  read_inheritable_attribute(:options) || {}
end

Instance Method Details

#execute(items = []) ⇒ Object

need override



43
44
45
# File 'lib/mashfeed/plugin.rb', line 43

def execute(items=[])
  items
end