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
# File 'lib/dayvan/design.rb', line 35

def attachment_path
  config_val('attachment_path', 'attachments_path', 'attachments') ||
    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



71
72
73
# File 'lib/dayvan/design.rb', line 71

def push
  doc.put to_json
end

#to_hashObject



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

def to_hash
  { '_rev' => rev,
    '_attachments' => attachments,
    'views' => views,
    'validate_doc_update' => validate_doc_update
  }.reject {|key, val| !val}
end

#to_jsonObject



67
68
69
# File 'lib/dayvan/design.rb', line 67

def to_json
  to_hash.to_json
end

#validate_doc_updateObject



49
50
51
# File 'lib/dayvan/design.rb', line 49

def validate_doc_update
  Dayvan::Validation.all(validate_doc_update_path)
end

#validate_doc_update_pathObject



53
54
55
56
# File 'lib/dayvan/design.rb', line 53

def validate_doc_update_path
  config_val('validation_path', 'validate_path', 'validation') ||
    Dayvan.project.dir.join('config','validation.coffee')
end

#view_pathObject



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

def view_path
  config_val('view_path', 'views_path', 'views') ||
    Dayvan.project.dir.join('views')
end

#viewsObject



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

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