Class: Fusuma::Plugin::Events::Records::IndexRecord

Inherits:
Record
  • Object
show all
Defined in:
lib/fusuma/plugin/events/records/index_record.rb

Overview

Vector Record have index

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#config_index, #config_param_types, #config_params, inherited, plugins

Methods included from CustomProcess

#fork

Constructor Details

#initialize(index:, position: :body, trigger: :oneshot, args: {}) ⇒ IndexRecord



17
18
19
20
21
22
23
# File 'lib/fusuma/plugin/events/records/index_record.rb', line 17

def initialize(index:, position: :body, trigger: :oneshot, args: {})
  super()
  @index = index
  @position = position
  @trigger = trigger
  @args = args
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



12
13
14
# File 'lib/fusuma/plugin/events/records/index_record.rb', line 12

def args
  @args
end

#indexObject

define gesture format



11
12
13
# File 'lib/fusuma/plugin/events/records/index_record.rb', line 11

def index
  @index
end

#positionObject (readonly)

Returns the value of attribute position.



12
13
14
# File 'lib/fusuma/plugin/events/records/index_record.rb', line 12

def position
  @position
end

#triggerObject (readonly)

Returns the value of attribute trigger.



12
13
14
# File 'lib/fusuma/plugin/events/records/index_record.rb', line 12

def trigger
  @trigger
end

Instance Method Details

#exist_on_conf?(index = @index) ⇒ Boolean



59
60
61
# File 'lib/fusuma/plugin/events/records/index_record.rb', line 59

def exist_on_conf?(index = @index)
  Config.search(index)
end

#mergable?Boolean



75
76
77
# File 'lib/fusuma/plugin/events/records/index_record.rb', line 75

def mergable?
  @position == :body
end

#merge(records:, index: @index) ⇒ IndexRecord, NilClass

FIXME: move to Config::Index



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/fusuma/plugin/events/records/index_record.rb', line 33

def merge(records:, index: @index)
  # FIXME: cache
  raise "position is NOT body: #{self}" unless mergable?

  if records.empty?
    if Config.find_execute_key(index)
      @index = index
      return self
    end
    return nil
  end

  record = records.shift
  new_index = case record.position
              when :surfix
                Config::Index.new([*index.keys, *record.index.keys])
              else
                raise "invalid index position: #{record}"
              end

  return unless exist_on_conf?(new_index)

  merge(records: records, index: new_index)
end

#trigger_priorityInteger



64
65
66
67
68
69
70
71
72
73
# File 'lib/fusuma/plugin/events/records/index_record.rb', line 64

def trigger_priority
  case @trigger
  when :oneshot
    10
  when :repeat
    100
  else
    1000
  end
end

#typeObject



25
26
27
# File 'lib/fusuma/plugin/events/records/index_record.rb', line 25

def type
  :index
end