Module: Fend::Plugins::Core::ClassMethods

Included in:
Fend
Defined in:
lib/fend.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#optsObject (readonly)

Returns the value of attribute opts.



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

def opts
  @opts
end

#validation_blockObject (readonly)

Returns the value of attribute validation_block.



48
49
50
# File 'lib/fend.rb', line 48

def validation_block
  @validation_block
end

Instance Method Details

#call(input) ⇒ Object



96
97
98
# File 'lib/fend.rb', line 96

def call(input)
  new.call(input)
end

#deprecation(message) ⇒ Object

Prints a deprecation warning to standard error.



101
102
103
# File 'lib/fend.rb', line 101

def deprecation(message)
  warn "FEND DEPRECATION WARNING: #{message}"
end

#inherited(subclass) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/fend.rb', line 50

def inherited(subclass)
  subclass.instance_variable_set(:@opts, opts.dup)
  subclass.opts.each do |key, value|
    if (value.is_a?(Array) || value.is_a?(Hash)) && !value.frozen?
      subclass.opts[key] = value.dup
    end
  end

  param_class = Class.new(self::Param)
  param_class.fend_class = subclass
  subclass.const_set(:Param, param_class)

  result_class = Class.new(self::Result)
  result_class.fend_class = subclass
  subclass.const_set(:Result, result_class)
end

#plugin(plugin, *args, &block) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/fend.rb', line 67

def plugin(plugin, *args, &block)
  plugin = Plugins.load_plugin(plugin) if plugin.is_a?(Symbol)
  plugin.load_dependencies(self, *args, &block) if plugin.respond_to?(:load_dependencies)

  include(plugin::InstanceMethods) if defined?(plugin::InstanceMethods)
  extend(plugin::ClassMethods) if defined?(plugin::ClassMethods)

  self::Param.send(:include, plugin::ParamMethods) if defined?(plugin::ParamMethods)
  self::Param.extend(plugin::ParamClassMethods) if defined?(plugin::ParamClassMethods)

  self::Result.send(:include, plugin::ResultMethods) if defined?(plugin::ResultMethods)
  self::Result.extend(plugin::ResultClassMethods) if defined?(plugin::ResultClassMethods)

  plugin.configure(self, *args, &block) if plugin.respond_to?(:configure)

  plugin
end

#validate(&block) ⇒ Object

Store validation block for later execution:

validate do |i|
  i.params(:foo) do |foo|
    # foo validation logic
  end
end


92
93
94
# File 'lib/fend.rb', line 92

def validate(&block)
  @validation_block = block
end