class ModablesDSL::DSL::Args

Attributes

args_h[R]

Public Class Methods

new() click to toggle source
# File lib/modables_dsl/dsl/arguments.rb, line 6
def initialize
  @args_h = Hash.new
end

Public Instance Methods

method_missing(meth, *args, &block) click to toggle source

Account for all possible arguments.

# File lib/modables_dsl/dsl/arguments.rb, line 45
def method_missing meth, *args, &block
  property meth, *args, &block
end
property(meth, *args, &block) click to toggle source
# File lib/modables_dsl/dsl/arguments.rb, line 10
def property meth, *args, &block

  # If requested convert underscrores to dashes.
  meth = ActiveSupport::Inflector.dasherize(meth.to_s) if args.include? :dash

  # If a block is passed it means we are building a hash.
  if block

    # If a :list is passed build an array of hashes and do not overwrite.
    if args.include? :list
      @args_h[meth] = Array.new if @args_h[meth].nil?

      if args.include? :json
        @args_h[meth] << ActiveSupport::JSON.encode(ModablesDSL::DSL.arguments(&block))
      else
        @args_h[meth] << ModablesDSL::DSL.arguments(&block)
      end

    # Else build a regular hash and overwrite with latest declaration.
    else
      if args.include? :json
        @args_h[meth] = ActiveSupport::JSON.encode(ModablesDSL::DSL.arguments(&block))
      else
        @args_h[meth] = ModablesDSL::DSL.arguments(&block)
      end
    end

  # Else its a String, Integer, Boolean or Array.
  else
    @args_h[meth] = args.last
  end

end
test(*args, &block) click to toggle source

For some reason if test is not defined explicitly the DSL errors.

# File lib/modables_dsl/dsl/arguments.rb, line 50
def test *args, &block
  property 'test', *args, &block
end