Class: Dayvan::Design

Inherits:
Object
  • Object
show all
Defined in:
lib/dayvan/design.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#configObject

Returns the value of attribute config.



3
4
5
# File 'lib/dayvan/design.rb', line 3

def config
  @config
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/dayvan/design.rb', line 3

def name
  @name
end

#revObject



26
27
28
29
# File 'lib/dayvan/design.rb', line 26

def rev
  @rev ||= JSON.parse(doc.get)['_rev']
rescue RestClient::ResourceNotFound
end

Class Method Details

.new_from_config(name, config = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/dayvan/design.rb', line 6

def self.new_from_config(name, config={})
  returning(new) do |d|
    if name.is_a?(Hash)
      d.name = name.delete('name')
      d.config = name
    else
      d.name = name
      d.config = config
    end
  end
end

Instance Method Details

#attachment_pathObject



35
36
37
38
39
# File 'lib/dayvan/design.rb', line 35

def attachment_path
  config['attachments'] ||
  config['attachment'] ||
  Dayvan.project.dir.join('public')
end

#attachmentsObject



31
32
33
# File 'lib/dayvan/design.rb', line 31

def attachments
  Dayvan::Attachment.all(attachment_path)
end

#docObject



18
19
20
# File 'lib/dayvan/design.rb', line 18

def doc
  Dayvan.project.db[id]
end

#idObject



22
23
24
# File 'lib/dayvan/design.rb', line 22

def id
  "_design/#{name}"
end

#pushObject



73
74
75
# File 'lib/dayvan/design.rb', line 73

def push
  doc.put to_json
end

#to_hashObject



61
62
63
64
65
66
67
# File 'lib/dayvan/design.rb', line 61

def to_hash
  hsh = { '_attachments' => attachments,
    'views' => views,
    'validate_doc_update' => validate_doc_update
  }
  rev ? hsh.merge('_rev' => rev) : hsh
end

#to_jsonObject



69
70
71
# File 'lib/dayvan/design.rb', line 69

def to_json
  to_hash.to_json
end

#validate_doc_updateObject



51
52
53
# File 'lib/dayvan/design.rb', line 51

def validate_doc_update
  Dayvan::Security.new(validate_doc_update_path)
end

#validate_doc_update_pathObject



55
56
57
58
# File 'lib/dayvan/design.rb', line 55

def validate_doc_update_path
  config['security'] ||
  Dayvan.project.dir.join('config','security.coffee')
end

#view_pathObject



45
46
47
48
49
# File 'lib/dayvan/design.rb', line 45

def view_path
  config['views'] ||
  config['view'] ||
  Dayvan.project.dir.join('views')
end

#viewsObject



41
42
43
# File 'lib/dayvan/design.rb', line 41

def views
  Dayvan::View.all(view_path)
end