Module: Lesmok::Acid::Droppable

Includes:
Helpers
Included in:
Drop
Defined in:
lib/lesmok/acid/drop.rb

Overview

Base module for creating liquid drops which defaults to allowing maximum access class for liquid drops used with Lesmok.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers

#cast, #melt, #solid

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args) ⇒ Object

Ensure before_method fallbacks are used both from liquid and when using drop directly.



49
50
51
# File 'lib/lesmok/acid/drop.rb', line 49

def method_missing(method_name, *args)
  (args.present?) ? super(method_name, *args) : before_method(method_name)
end

Instance Attribute Details

#acid_optionsObject (readonly)

Any customization options.



13
14
15
# File 'lib/lesmok/acid/drop.rb', line 13

def acid_options
  @acid_options
end

#source_objectObject (readonly)

Object we delegate to



12
13
14
# File 'lib/lesmok/acid/drop.rb', line 12

def source_object
  @source_object
end

Instance Method Details

#allow_delegating_method_to_source?(name) ⇒ Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/lesmok/acid/drop.rb', line 40

def allow_delegating_method_to_source?(name)
  @source_object.respond_to?(name) # TODO: && !name =~ /(\!\=)$/
end

#before_method(method_name) ⇒ Object

We default to sending anything through to the source object.



30
31
32
33
34
35
36
37
38
# File 'lib/lesmok/acid/drop.rb', line 30

def before_method(method_name)
  if allow_delegating_method_to_source?(method_name)
    return @source_object.send(method_name)
  else
    msg = "[#{self.class}] The method `#{method_name}` is not defined on #{@source_object.inspect[0..127]}."
    Lesmok.logger.warn(msg) if Lesmok.config.debugging?
    raise NotImplementedError.new(msg) if Lesmok.config.raise_errors?
  end
end

#initialize(source, opts = {}) ⇒ Object



14
15
16
17
# File 'lib/lesmok/acid/drop.rb', line 14

def initialize(source, opts = {})
  @source_object = source
  @acid_options = opts
end

#respond_to_missing?(method_name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/lesmok/acid/drop.rb', line 44

def respond_to_missing?(method_name, include_private = false)
  allow_delegating_method_to_source?(method_name) || super
end

#to_liquidObject

Liquify…



20
21
22
# File 'lib/lesmok/acid/drop.rb', line 20

def to_liquid
  self
end

#to_solidObject

Solidify



25
26
27
# File 'lib/lesmok/acid/drop.rb', line 25

def to_solid
  @source_object
end