Sha256: d3b69473fb6055772cb5553d95a1c3d509d4090f5e5aca97b7b5bf0ee740b588

Contents?: true

Size: 1.17 KB

Versions: 5

Compression:

Stored size: 1.17 KB

Contents

module Mirage
  class Templates
    include HTTParty
    def initialize base_url
      @url = "#{base_url}/templates"
      @requests = Requests.new(base_url)
      @default_config = Template::Configuration.new
    end

    def default_config &block
      return @default_config unless block_given?
      calling_instance = eval "self", block.binding
      @default_config.caller_binding = calling_instance
      @default_config.instance_eval &block
      @default_config.caller_binding = nil
    end

    def delete_all
      self.class.delete(@url)
      @requests.delete_all
    end

    def put *args, &block
      if args.first.class.is_a?(Template::Model)
        template = args.first
        template.endpoint "#{@url}/#{template.endpoint}" unless template.endpoint.to_s.start_with?(@url)
      else
        endpoint, response = args
        template = Mirage::Template.new  "#{@url}/#{endpoint}", response, @default_config
      end

      if block
        calling_instance = eval "self", block.binding
        template.caller_binding = calling_instance
        template.instance_exec(template,&block)
        template.caller_binding = nil
      end

      template.create
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
mirage-3.0.0.alpha.16 lib/mirage/client/templates.rb
mirage-3.0.0.alpha.15 lib/mirage/client/templates.rb
mirage-3.0.0.alpha.14 lib/mirage/client/templates.rb
mirage-3.0.0.alpha.13 lib/mirage/client/templates.rb
mirage-3.0.0.alpha.12 lib/mirage/client/templates.rb