Class: TrustyCms::ResourceResponses::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/trusty_cms/resource_responses.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeResponse

Returns a new instance of Response.



68
69
70
71
72
# File 'lib/trusty_cms/resource_responses.rb', line 68

def initialize
  @publish_formats = []
  @blocks = {}
  @block_order = []
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



110
111
112
113
114
115
116
117
118
119
# File 'lib/trusty_cms/resource_responses.rb', line 110

def method_missing(method, *args, &block)
  if block_given?
    @blocks[method] = block
    @block_order << method unless @block_order.include?(method)
  elsif args.empty?
    @block_order << method
  else
    super
  end
end

Instance Attribute Details

#block_orderObject (readonly)

Returns the value of attribute block_order.



66
67
68
# File 'lib/trusty_cms/resource_responses.rb', line 66

def block_order
  @block_order
end

#blocksObject (readonly)

Returns the value of attribute blocks.



66
67
68
# File 'lib/trusty_cms/resource_responses.rb', line 66

def blocks
  @blocks
end

#publish_blockObject (readonly)

Returns the value of attribute publish_block.



66
67
68
# File 'lib/trusty_cms/resource_responses.rb', line 66

def publish_block
  @publish_block
end

#publish_formatsObject (readonly)

Returns the value of attribute publish_formats.



66
67
68
# File 'lib/trusty_cms/resource_responses.rb', line 66

def publish_formats
  @publish_formats
end

Instance Method Details

#default(&block) ⇒ Object



82
83
84
85
86
87
# File 'lib/trusty_cms/resource_responses.rb', line 82

def default(&block)
  if block_given?
    @default = block
  end
  @default
end

#each_formatObject



104
105
106
107
108
# File 'lib/trusty_cms/resource_responses.rb', line 104

def each_format
  @block_order.each do |format|
    yield format, @blocks[format] if block_given?
  end
end

#each_publishedObject



98
99
100
101
102
# File 'lib/trusty_cms/resource_responses.rb', line 98

def each_published
  publish_formats.each do |format|
    yield format, publish_block if block_given?
  end
end

#initialize_copy(orig) ⇒ Object



74
75
76
77
78
79
80
# File 'lib/trusty_cms/resource_responses.rb', line 74

def initialize_copy(orig)
  @publish_formats = orig.publish_formats.dup
  @blocks = orig.blocks.dup
  @block_order = orig.block_order.dup
  @publish_block = orig.publish_block.dup if orig.publish_block
  @default = orig.default.dup if orig.default
end

#publish(*formats, &block) ⇒ Object



89
90
91
92
93
94
95
96
# File 'lib/trusty_cms/resource_responses.rb', line 89

def publish(*formats, &block)
  @publish_formats.concat(formats)
  if block_given?
    @publish_block = block
  else
    raise ArgumentError, 'Block required to publish' unless @publish_block
  end
end