Class: Mygithub::MilkodeAccessor

Inherits:
Object
  • Object
show all
Defined in:
lib/mygithub/milkode_accessor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dbdir) ⇒ MilkodeAccessor

Returns a new instance of MilkodeAccessor.



17
18
19
20
21
# File 'lib/mygithub/milkode_accessor.rb', line 17

def initialize(dbdir)
  @dbdir = dbdir
  @cdstk = Milkode::Cdstk.new($stdout, @dbdir)
  @yaml = YamlFileWrapper.load_if(@dbdir)
end

Instance Attribute Details

#dbdirObject (readonly)

Returns the value of attribute dbdir.



15
16
17
# File 'lib/mygithub/milkode_accessor.rb', line 15

def dbdir
  @dbdir
end

Instance Method Details

#add(args) ⇒ Object



48
49
50
# File 'lib/mygithub/milkode_accessor.rb', line 48

def add(args)
  @cdstk.add(args, {:same_add => true})
end

#cdweb_execute_with_options(stdout, options) ⇒ Object

milkode/cdweb/cli_cdweb.rb:95



90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/mygithub/milkode_accessor.rb', line 90

def cdweb_execute_with_options(stdout, options)
  dbdir = File.expand_path(options[:DbDir])

  # 使用するデータベースの位置設定
  Milkode::Database.setup(dbdir)

  # サーバースクリプトのある場所へ移動
  FileUtils.cd(File.join File.dirname(__FILE__), 'web')

  # Rackサーバー起動
  Rack::Server.start(options)
end

#create_milkweb_yaml(icon_url) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/mygithub/milkode_accessor.rb', line 31

def create_milkweb_yaml(icon_url)
  filename = File.join(@dbdir, 'milkweb.yaml')

  File.open(filename, "w") do |f|
    f.write <<EOF
---
:home_title : "MyGithub"
:home_icon  : #{icon_url}

:header_title: "MyGithub"
:header_icon : #{icon_url}

:display_about_milkode: false
EOF
  end
end

#database_exitst?Boolean

Returns:

  • (Boolean)


60
61
62
# File 'lib/mygithub/milkode_accessor.rb', line 60

def database_exitst?
  @yaml && @yaml.contents.size > 0
end

#exist?(name) ⇒ Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/mygithub/milkode_accessor.rb', line 56

def exist?(name)
  !@yaml.find_name(name).nil?
end

#initObject



23
24
25
26
27
28
29
# File 'lib/mygithub/milkode_accessor.rb', line 23

def init
  unless File.exist? @dbdir
    FileUtils.mkdir_p @dbdir
    @cdstk.init({})
    @yaml = YamlFileWrapper.load_if(@dbdir)        
  end
end

#update(args) ⇒ Object



52
53
54
# File 'lib/mygithub/milkode_accessor.rb', line 52

def update(args)
  @cdstk.update(args, {})      
end

#web(options) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/mygithub/milkode_accessor.rb', line 64

def web(options)
  opts = {
    :environment   => ENV['RACK_ENV'] || "development",
    :pid           => nil,
    :Port          => options[:port],
    :Host          => options[:host],
    :AccessLog     => [],
    :config        => "config.ru",
    # ----------------------------
    :server        => options[:server],
    :LaunchBrowser => !options[:no_browser],
    :LaunchURL     => database_exitst? ? nil : '/login',
    :DbDir         => options[:db],
  }

  # init
  init

  # open
  @cdstk.assert_compatible

  # Milkode::CLI_Cdweb.execute_with_options($stdout, opts)
  cdweb_execute_with_options($stdout, opts)
end