Class: Flydata::PluginSupport::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/flydata/plugin_support/context.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts) ⇒ Context

Returns a new instance of Context.


43
44
45
46
47
48
49
50
51
52
# File 'lib/flydata/plugin_support/context.rb', line 43

def initialize(opts)
  missing_opts = self.class.mandatory_opts - opts.keys
  unless (missing_opts.empty?)
    raise "Mandatory option(s) are missing: #{missing_opts.join(', ')}"
  end

  opts.each do |k, v|
    self.instance_variable_set(:"@#{k}", v)
  end
end

Class Method Details

.mandatory_optsObject


5
6
7
# File 'lib/flydata/plugin_support/context.rb', line 5

def self.mandatory_opts
  @mandatory_opts ||= []
end

.optional_optsObject


9
10
11
# File 'lib/flydata/plugin_support/context.rb', line 9

def self.optional_opts
  @optional_opts ||= []
end

.register_mandatory_opts(*opts) ⇒ Object


13
14
15
16
17
18
19
20
# File 'lib/flydata/plugin_support/context.rb', line 13

def self.register_mandatory_opts(*opts)
  @mandatory_opts ||= []
  opts.each {|opt|
    @mandatory_opts << opt.to_sym
    attr_accessor opt
  }
  nil
end

.register_optional_opts(*opts) ⇒ Object


22
23
24
25
26
27
28
29
# File 'lib/flydata/plugin_support/context.rb', line 22

def self.register_optional_opts(*opts)
  @optional_opts ||= []
  opts.each {|opt|
    @optional_opts << opt.to_sym
    attr_accessor opt
  }
  nil
end

Instance Method Details

#source_pos_classObject


54
55
56
# File 'lib/flydata/plugin_support/context.rb', line 54

def source_pos_class
  self.class::SOURCE_POS_CLASS
end