-
Notifications
You must be signed in to change notification settings - Fork 205
New amber watch config #865
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 24 commits
8abe79c
994e730
7925382
d148ce9
b65e3fb
7f49bd7
19dc8d6
10e9f60
4995c92
65f81aa
36f7b3a
11a014f
dbd3163
20d9892
dd65e57
55312e9
08a3e17
a31f347
ba2abe4
ee8940a
c405408
235add8
a4a094b
b6e21a8
25443c3
080f96c
0521e1d
a3167ed
b88fdc2
ff5f794
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,18 +1,26 @@ | ||
| require "yaml" | ||
|
|
||
| module Amber::CLI | ||
| def self.config | ||
| if File.exists? AMBER_YML | ||
| Config.from_yaml File.read(AMBER_YML) | ||
| else | ||
| Config.new | ||
| end | ||
| rescue ex : YAML::ParseException | ||
| logger.error "Couldn't parse #{AMBER_YML} file", "Watcher", :red | ||
| exit 1 | ||
| end | ||
|
|
||
| class Config | ||
| property database : String = "pg" | ||
| property language : String = "slang" | ||
| property model : String = "granite" | ||
| property recipe : (String | Nil) = nil | ||
| property recipe_source : (String | Nil) = nil | ||
| alias Watch = Hash(String, Hash(String, Array(String))) | ||
|
|
||
| getter database : String = "pg" | ||
| getter language : String = "slang" | ||
| getter model : String = "granite" | ||
| getter recipe : String? | ||
| getter recipe_source : String? | ||
| getter watch : Watch? | ||
|
|
||
| def initialize | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can remove this initializer since is not doing anything
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I remove the initialize then I can't use Let me add a comment about this 👍 |
||
| end | ||
|
|
@@ -21,8 +29,9 @@ module Amber::CLI | |
| database: {type: String, default: "pg"}, | ||
| language: {type: String, default: "slang"}, | ||
| model: {type: String, default: "granite"}, | ||
| recipe: String | Nil, | ||
| recipe_source: String | Nil | ||
| recipe: String?, | ||
| recipe_source: String?, | ||
| watch: Watch? | ||
| ) | ||
| end | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| module Amber | ||
| class FileWatcher | ||
| @file_timestamps = {} of String => String | ||
|
|
||
| private def get_timestamp(file : String) | ||
| File.info(file).modification_time.to_s("%Y%m%d%H%M%S") | ||
| end | ||
|
|
||
| def scan_files(files) | ||
| Dir.glob(files) do |file| | ||
| timestamp = get_timestamp(file) | ||
| if @file_timestamps[file]? != timestamp | ||
| @file_timestamps[file] = timestamp | ||
| yield file | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Helpers is a module and the
.waitcall makes it look like is an instance of an object and the method.runis deceiving since its just creating an instance of Process. I like that this method has some helpful arguments defaults and in that case I recommend to useclass CLIProcess < Processand overwrite the run method with defaults and call super on it.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks cleaner, Nice idea! 👍