lib/gmail-britta/single_write_accessors.rb
# Defines a string-typed filter accessor DSL method.  Generates
# the `[name]`, `get_[name]` and `output_[name]` methods.
# @param name [Symbol] the name of the accessor method
# @param gmail_name [String] the name of the attribute in the
#   gmail Atom export
Defines a string-typed filter accessor DSL method.
Defines a string - typed filter accessor DSL method .
def single_write_accessor(name, gmail_name, &block)
        direct_single_write_accessors[name] = gmail_name
        ivar = ivar_name(name)
        define_method(name) do |words|
          if instance_variable_get(ivar) and instance_variable_get(ivar) != []
            raise "Only one use of #{name} is permitted per filter"
          end
          instance_variable_set(ivar, words)
        end
        get(name, ivar)
        if block_given?
          define_method("output_#{name}") do
            instance_variable_get(ivar) && block.call(instance_variable_get(ivar)) unless instance_variable_get(ivar) == []
          end
        else
          output(name, ivar)
        end
      end
def single_write_accessor ( name , gmail_name , & block ) direct_single_write_accessors [ name ] = gmail_name ivar = ivar_name ( name ) define_method ( name ) do | words | if instance_variable_get ( ivar ) and instance_variable_get ( ivar ) != [ ] raise "Only one use of #{name} is permitted per filter" end instance_variable_set ( ivar , words ) end get ( name , ivar ) if block_given? define_method ( "output_#{name}" ) do instance_variable_get ( ivar ) && block . call ( instance_variable_get ( ivar ) ) unless instance_variable_get ( ivar ) == [ ] end else output ( name , ivar ) end end
Defines a string-typed filter accessor DSL method.
Defines a string - typed filter accessor DSL method .
name
the name of the accessor method
the name of the accessor method
gmail_name
the name of the attribute in the gmail Atom export
the name of the attribute in the gmail Atom export
block
<not_specific>