Sha256: d63fc8d368a172d558440e70ce7f22f3cf77aa14a18debaed7151976707f4fb9

Contents?: true

Size: 1.07 KB

Versions: 1

Compression:

Stored size: 1.07 KB

Contents

require 'vedeu/api/line'
require 'vedeu/api/store'

module Vedeu
  module API
    InterfaceNotSpecified = Class.new(StandardError)

    def render(object = nil)
      Vedeu::View.render(object)
    end

    def view(name = '', &block)
      Vedeu::API::View.build(name, &block)
    end

    class View
      def self.build(name = '', &block)
        new(name).build(&block)
      end

      def initialize(name = '')
        fail Vedeu::API::InterfaceNotSpecified if name.nil? || name.empty?

        @name = name.to_s
      end

      def build(&block)
        @self_before_instance_eval = eval 'self', block.binding

        self.instance_eval(&block) if block_given?

        attributes
      end

      def line(&block)
        attributes[:lines] << API::Line.build(&block)
      end

      def attributes
        @_attributes ||= { name: name, lines: [] }
      end

      def name
        return @name if Store.query(@name)
      end

      private

      def method_missing(method, *args, &block)
        @self_before_instance_eval.send method, *args, &block
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
vedeu-0.1.8 lib/vedeu/api/view.rb