Class: MemoRack::PageInfo
- Extended by:
- Plugin
- Defined in:
- lib/memorack/pageinfo.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#max_lines ⇒ Object
Returns the value of attribute max_lines.
Class Method Summary collapse
Instance Method Summary collapse
-
#app ⇒ Object
実行アプリケーション.
-
#git? ⇒ Boolean
git で管理されているか?.
-
#initialize(path, hash = nil, parent = {}, ifnone = nil) ⇒ PageInfo
constructor
A new instance of PageInfo.
-
#log ⇒ Object
git log で更新日時一覧を取得する.
-
#parse(*info_list) ⇒ Object
ファイルを解析.
-
#parse_end?(line, n) ⇒ Boolean
ファイル解析の終了か?.
-
#value_to_time(value) ⇒ Object
値を Timeクラスに変換する.
- #values ⇒ Object
Methods included from Plugin
<=>, [], extnames, inherited, member?, plugins, priority
Methods inherited from Locals
#[], #context, #context=, define_key, #define_key, #has_key?, #merge, #super_has_key?, #value, value_method, #value_method?
Constructor Details
#initialize(path, hash = nil, parent = {}, ifnone = nil) ⇒ PageInfo
Returns a new instance of PageInfo.
13 14 15 16 17 18 19 20 21 |
# File 'lib/memorack/pageinfo.rb', line 13 def initialize(path, hash = nil, parent = {}, ifnone = nil) super ifnone @path = path merge!(hash) if hash @max_lines = 5 @parent = parent end |
Instance Attribute Details
#max_lines ⇒ Object
Returns the value of attribute max_lines.
11 12 13 |
# File 'lib/memorack/pageinfo.rb', line 11 def max_lines @max_lines end |
Class Method Details
.define_keys(*keys, &block) ⇒ Object
111 112 113 114 115 116 117 |
# File 'lib/memorack/pageinfo.rb', line 111 def self.define_keys(*keys, &block) block = lambda { |key| values[key] || parse(key) } unless block keys.each { |name| define_key(name, &block) } end |
Instance Method Details
#app ⇒ Object
実行アプリケーション
66 67 68 69 70 71 |
# File 'lib/memorack/pageinfo.rb', line 66 def app begin @parent.app rescue end end |
#git? ⇒ Boolean
git で管理されているか?
74 75 76 77 78 79 80 81 |
# File 'lib/memorack/pageinfo.rb', line 74 def git? if @git == nil @git ||= File.exists?(File.join(app.root, '.git')) @git ||= File.exists?(File.join(app.root, '../.git')) end @git end |
#log ⇒ Object
git log で更新日時一覧を取得する
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/memorack/pageinfo.rb', line 84 def log unless @log @log = [] return @log unless git? begin dir, fname = File.split(@path) Dir.chdir(dir) { |dir| log << File::Stat.new(fname).mtime if `git status` =~ /modified:\s+#{fname}/ `git log --pretty='%ad' --date iso '#{fname}'`.each_line { |line| @log << line } } rescue end end @log end |
#parse(*info_list) ⇒ Object
ファイルを解析
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/memorack/pageinfo.rb', line 28 def parse(*info_list) methods = {} info_list.each { |info| m = "accept_#{info}" methods[info] = m if respond_to?(m) } open(@path, 'r') { |file| prev = nil n = 1 until methods.empty? break unless line = file.gets break if parse_end?(line, n) methods.each { |key, m| v = send(m, line, prev) if v values[key] = v methods.delete(key) end } prev = line n += 1 end } values[info_list.first] end |
#parse_end?(line, n) ⇒ Boolean
ファイル解析の終了か?
61 62 63 |
# File 'lib/memorack/pageinfo.rb', line 61 def parse_end?(line, n) max_lines < n end |
#value_to_time(value) ⇒ Object
値を Timeクラスに変換する
106 107 108 109 |
# File 'lib/memorack/pageinfo.rb', line 106 def value_to_time(value) value = Time.parse(value) if value.kind_of?(String) value end |
#values ⇒ Object
23 24 25 |
# File 'lib/memorack/pageinfo.rb', line 23 def values @values ||= {} end |