Class: Spree::SetupTasks::Definition

Inherits:
Object
  • Object
show all
Defined in:
app/models/spree/setup_tasks.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, position:, done:, **options) ⇒ Definition

Returns a new instance of Definition.

Raises:

  • (ArgumentError)


27
28
29
30
31
32
33
34
# File 'app/models/spree/setup_tasks.rb', line 27

def initialize(key, position:, done:, **options)
  raise ArgumentError, "done: must respond to #call" unless done.respond_to?(:call)

  @key = key.to_sym
  @position = position
  @done = done
  @if = options[:if]
end

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key.



25
26
27
# File 'app/models/spree/setup_tasks.rb', line 25

def key
  @key
end

#positionObject (readonly)

Returns the value of attribute position.



25
26
27
# File 'app/models/spree/setup_tasks.rb', line 25

def position
  @position
end

Instance Method Details

#available?(subject) ⇒ Boolean

Returns whether the task applies to this subject at all.

Parameters:

  • subject (Object)

    the record the checklist belongs to

Returns:

  • (Boolean)

    whether the task applies to this subject at all



44
45
46
# File 'app/models/spree/setup_tasks.rb', line 44

def available?(subject)
  @if.nil? || !!@if.call(subject)
end

#done?(subject) ⇒ Boolean

Returns whether the task is complete.

Parameters:

  • subject (Object)

    the record the checklist belongs to (e.g. a store)

Returns:

  • (Boolean)

    whether the task is complete



38
39
40
# File 'app/models/spree/setup_tasks.rb', line 38

def done?(subject)
  !!@done.call(subject)
end