class Flatter::Extension::Builder
Constants
- ExtensionBlockAlreadyDefined
Public Class Methods
extends(target_name)
click to toggle source
# File lib/flatter/extension/builder.rb, line 5 def self.extends(target_name) @target_name = target_name end
new(ext)
click to toggle source
# File lib/flatter/extension/builder.rb, line 13 def initialize(ext) @ext = ext @new_options = [] end
target_name()
click to toggle source
# File lib/flatter/extension/builder.rb, line 9 def self.target_name @target_name end
Public Instance Methods
add_option(*options)
click to toggle source
# File lib/flatter/extension/builder.rb, line 18 def add_option(*options) @new_options.concat options extend(&Proc.new) if block_given? end
Also aliased as: add_options
extend(&block)
click to toggle source
# File lib/flatter/extension/builder.rb, line 24 def extend(&block) fail ExtensionBlockAlreadyDefined if @extension_block.present? @extension_block = block end
extends?()
click to toggle source
# File lib/flatter/extension/builder.rb, line 29 def extends? @new_options.present? || @extension_block.present? end
Private Instance Methods
extension()
click to toggle source
# File lib/flatter/extension/builder.rb, line 33 def extension extension = Module.new extension.module_eval(new_option_helpers) if @new_options.present? extension.module_eval(&@extension_block) if @extension_block.present? @ext.const_set(self.class.target_name, extension) extension end
fail_if_options_defined!()
click to toggle source
# File lib/flatter/extension/builder.rb, line 42 def fail_if_options_defined! options_method = self.class.target_name.underscore + '_options' options = ::Flatter::Mapper.public_send(options_method) already_defined = options & @new_options if already_defined.present? fail RuntimeError, "Cannot extend with #{@ext.name}: options #{already_defined} already defined" end end
new_option_helpers()
click to toggle source
# File lib/flatter/extension/builder.rb, line 53 def new_option_helpers code = @new_options.map do |option| <<-RUBY def #{option} options[:#{option}] end def #{option}? options.key?(:#{option}) end RUBY end code.join("\n") end