mirror of https://github.com/Calamitous/iris.git
Add version and various cleanup
This commit is contained in:
parent
7628afdfb7
commit
ccf2eb0a4e
13
iris.rb
13
iris.rb
|
@ -25,6 +25,7 @@ require 'json'
|
||||||
require 'etc'
|
require 'etc'
|
||||||
|
|
||||||
class Config
|
class Config
|
||||||
|
VERSION = '1.0.0'
|
||||||
CONFIG_FILE = "#{ENV['HOME']}/.iris.config.json"
|
CONFIG_FILE = "#{ENV['HOME']}/.iris.config.json"
|
||||||
MESSAGE_FILE = "#{ENV['HOME']}/.iris.messages"
|
MESSAGE_FILE = "#{ENV['HOME']}/.iris.messages"
|
||||||
|
|
||||||
|
@ -49,15 +50,16 @@ end
|
||||||
class IrisFile
|
class IrisFile
|
||||||
def self.load_messages(filepath = Config::MESSAGE_FILE)
|
def self.load_messages(filepath = Config::MESSAGE_FILE)
|
||||||
# TODO create file for current user
|
# TODO create file for current user
|
||||||
|
# For logger: puts "Checking #{filepath}"
|
||||||
return [] unless File.exists?(filepath)
|
return [] unless File.exists?(filepath)
|
||||||
|
|
||||||
|
# For logger: puts "Found, parsing #{filepath}..."
|
||||||
# TODO gracefully handle non-json files
|
# TODO gracefully handle non-json files
|
||||||
payload = JSON.parse(File.read(filepath))
|
payload = JSON.parse(File.read(filepath))
|
||||||
raise 'Invalid File!' unless payload.is_a?(Array)
|
raise 'Invalid File!' unless payload.is_a?(Array)
|
||||||
|
|
||||||
uid = File.stat(filepath).uid
|
uid = File.stat(filepath).uid
|
||||||
username = Etc.getpwuid(uid).name
|
username = Etc.getpwuid(uid).name
|
||||||
p username
|
|
||||||
|
|
||||||
payload.map do |message_json|
|
payload.map do |message_json|
|
||||||
new_message = Message.load(message_json)
|
new_message = Message.load(message_json)
|
||||||
|
@ -73,9 +75,9 @@ end
|
||||||
|
|
||||||
class Corpus
|
class Corpus
|
||||||
def self.load
|
def self.load
|
||||||
@@corpus = Config.find_files.map { |filepath| IrisFile.load_messages(filepath) }.flatten.sort_by(&:timestamp)
|
@@corpus = Config.find_files.map { |filepath| IrisFile.load_messages(filepath) }.flatten.sort_by(&:timestamp)
|
||||||
@@topics = @@corpus.select{ |m| m.parent == nil }
|
@@topics = @@corpus.select{ |m| m.parent == nil }
|
||||||
@@my_corpus = IrisFile.load_messages
|
@@my_corpus = IrisFile.load_messages.sort_by(&:timestamp)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.all
|
def self.all
|
||||||
|
@ -134,8 +136,6 @@ class Message
|
||||||
|
|
||||||
def save!
|
def save!
|
||||||
new_corpus = Corpus.mine << self
|
new_corpus = Corpus.mine << self
|
||||||
p new_corpus
|
|
||||||
p new_corpus.to_json
|
|
||||||
IrisFile.write_corpus(new_corpus.to_json)
|
IrisFile.write_corpus(new_corpus.to_json)
|
||||||
Corpus.load
|
Corpus.load
|
||||||
end
|
end
|
||||||
|
@ -150,7 +150,6 @@ class Message
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_json(*args)
|
def to_json(*args)
|
||||||
p args
|
|
||||||
{
|
{
|
||||||
hash: hash,
|
hash: hash,
|
||||||
edit_hash: edit_hash,
|
edit_hash: edit_hash,
|
||||||
|
|
Loading…
Reference in New Issue