Class: DynarexUsersBlog

Inherits:
Object
  • Object
show all
Defined in:
lib/dynarex-usersblog.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ DynarexUsersBlog

Returns a new instance of DynarexUsersBlog.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/dynarex-usersblog.rb', line 12

def initialize(options={})

  o = {file_path: '.', user: ''}.merge(options)

  threads = []
  threads << Thread.new{

    unless o[:user].empty? then      

      @current_user = o[:user]
      @file_path = o[:file_path]
      user_file_path = "%s/users/%s" % [@file_path,  @current_user]

      FileUtils.mkdir_p user_file_path
      @hc_blog = HashCache.new
     switch_user o[:user]
    end
  }

  threads << Thread.new{@master_blog = DynarexBlog.new o[:file_path]}
  threads.each{|thread| thread.join}
  
  super()
end

Instance Method Details

#create_entry(blog_params = {}, user = nil) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/dynarex-usersblog.rb', line 37

def create_entry(blog_params={}, user=nil)
  switch_user user unless user.nil? or user.empty? or @current_user == user
  blog_params.merge!({user: @current_user})
  @user_blog.create_entry blog_params
  @master_blog.id = @user_blog.id.to_i - 1
  @master_blog.create_entry blog_params
end

#delete(id = 0) ⇒ Object



45
46
47
48
# File 'lib/dynarex-usersblog.rb', line 45

def delete(id=0)
  @user_blog.delete id
  @master_blog.delete id
end

#entry(id) ⇒ Object



63
64
65
# File 'lib/dynarex-usersblog.rb', line 63

def entry(id)
  @master_blog.entry(id)
end

#page(n = 0) ⇒ Object



50
51
52
# File 'lib/dynarex-usersblog.rb', line 50

def page(n=0)
  @master_blog.page(n)
end

#switch_user(user) ⇒ Object



77
78
79
80
81
82
# File 'lib/dynarex-usersblog.rb', line 77

def switch_user(user)

  user_file_path = "%s/users/%s" % [@file_path,  user]
  @user_blog = @hc_blog.read(user) { DynarexBlog.new user_file_path }
  @current_blog = @user_blog
end

#tag(tag_name) ⇒ Object



54
55
56
# File 'lib/dynarex-usersblog.rb', line 54

def tag(tag_name)
  @master_blog.tag(tag_name)
end

#tagsObject



67
68
69
# File 'lib/dynarex-usersblog.rb', line 67

def tags
  @master_blog.tags
end

#update_entry(user, id = 0, h = {}) ⇒ Object



71
72
73
74
75
# File 'lib/dynarex-usersblog.rb', line 71

def update_entry(user, id=0, h={})
  switch_user user unless @current_user == user
  @user_blog.update(id, h)
  @master_blog.update(id, h)
end

#user(username) ⇒ Object



58
59
60
61
# File 'lib/dynarex-usersblog.rb', line 58

def user(username)
  (@current_user == username ? @current_user : switch_user(username))
  self
end