Class: Mirage::Templates

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/mirage/client/templates.rb

Instance Method Summary collapse

Constructor Details

#initialize(base_url) ⇒ Templates

Returns a new instance of Templates.



5
6
7
8
9
# File 'lib/mirage/client/templates.rb', line 5

def initialize base_url
  @url = "#{base_url}/templates"
  @requests = Requests.new(base_url)
  @default_config = Template::Configuration.new
end

Instance Method Details

#default_config(&block) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/mirage/client/templates.rb', line 11

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

#delete_allObject



19
20
21
22
# File 'lib/mirage/client/templates.rb', line 19

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

#put(*args, &block) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/mirage/client/templates.rb', line 24

def put *args, &block
  if args.first.class.is_a?(Template::Model)
    template = args.first
    template = template.clone
    template.endpoint "#{@url}/#{template.endpoint}"
  else

    endpoint, template = args
    if template.class.is_a?(Template::Model)
      template = template.clone
      template.endpoint "#{@url}/#{endpoint}"
    else
      template = Mirage::Template.new("#{@url}/#{endpoint}", template, @default_config)
    end

  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