Class: Compony::ComponentMixins::Default::Standalone::ResourcefulVerbDsl

Inherits:
VerbDsl
  • Object
show all
Defined in:
lib/compony/component_mixins/default/standalone/resourceful_verb_dsl.rb

Overview

Verb DSL override specifically for resourceful components

See Also:

Constant Summary

Constants inherited from VerbDsl

VerbDsl::AVAILABLE_VERBS

Instance Method Summary collapse

Methods inherited from VerbDsl

#authorize, #default_config, #respond

Constructor Details

#initializeResourcefulVerbDsl

Returns a new instance of ResourcefulVerbDsl.



10
11
12
13
14
# File 'lib/compony/component_mixins/default/standalone/resourceful_verb_dsl.rb', line 10

def initialize(...)
  # All resourceful components have a load_data_block, which defaults to the one defined in Resource, defaulting to finding the record.
  @load_data_block = proc { evaluate_with_backfire(&@global_load_data_block) }
  super
end

Instance Method Details

#assign_attributes(&block) ⇒ Object (protected)

DSL This is called after load_data. The block is expected to assign data from params as attributes of @data. If this method gets never called, the verb config will not contain a assign_attributes block. If called without a block, the verb config will call the global_assign_attributes block defined in Resource.



37
38
39
40
41
42
43
# File 'lib/compony/component_mixins/default/standalone/resourceful_verb_dsl.rb', line 37

def assign_attributes(&block)
  if block_given?
    @assign_attributes_block = block
  else
    @assign_attributes_block = proc { evaluate_with_backfire(&@global_assign_attributes_block) }
  end
end

#load_data(&block) ⇒ Object (protected)

DSL This is the first step in the life cycle. The block is expected to assign something to @data.



29
30
31
# File 'lib/compony/component_mixins/default/standalone/resourceful_verb_dsl.rb', line 29

def load_data(&block)
  @load_data_block = block
end

#store_data(&block) ⇒ Object (protected)

DSL This is called after authorization. The block is expected to write back to the database. If this method gets never called, the verb config will not contain a store_data block. If called without a block, the verb config will call the global_store_data block defined in Resource.



49
50
51
52
53
54
55
# File 'lib/compony/component_mixins/default/standalone/resourceful_verb_dsl.rb', line 49

def store_data(&block)
  if block_given?
    @store_data_block = block
  else
    @store_data_block = proc { evaluate_with_backfire(&@global_store_data_block) }
  end
end

#to_conf(provide_defaults:) ⇒ Object

For internal usage only, processes the block and returns a config hash.



17
18
19
20
21
22
23
# File 'lib/compony/component_mixins/default/standalone/resourceful_verb_dsl.rb', line 17

def to_conf(provide_defaults:, &)
  return super.deep_merge({
                            load_data_block:         @load_data_block,
                            assign_attributes_block: @assign_attributes_block,
                            store_data_block:        @store_data_block
                          }).compact
end