forked from dtan4/terraforming
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: add the ability to only generate data for objects matching confi…
…gurable patterns.
- Loading branch information
Showing
28 changed files
with
277 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module Terraforming | ||
module Matcher | ||
# matches a set of properties | ||
class CompoundMatcher | ||
def initialize(patterns) | ||
@matchers = patterns.map{|p| Matcher::PropertyMatcher.new(p)} | ||
end | ||
|
||
def match(anything) | ||
return false unless @matchers | ||
return @matchers.inject(true){|result, matcher| result && matcher.match(anything) } | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module Terraforming | ||
module Matcher | ||
# matches anything by default | ||
class DefaultMatcher | ||
def match(anything) | ||
true | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
module Terraforming | ||
module Matcher | ||
# matches a particular property | ||
class PropertyMatcher | ||
# string in the form of key=value or key=~value | ||
# if the latter, uses a regular expression match instead of a string equals | ||
def initialize(definition) | ||
@key, @condition = definition.split("=", 2) | ||
if @condition =~ /^~/ | ||
@condition = Regexp.new(@condition[1..@condition.length]) | ||
end | ||
end | ||
|
||
# returns true if the property's value for key matches the given value, false otherwise | ||
def match(anything) | ||
return false unless anything | ||
case @condition | ||
when String | ||
return resolve(anything).to_s == @condition | ||
when Regexp | ||
return nil != (resolve(anything).to_s =~ @condition) | ||
else | ||
return false | ||
end | ||
end | ||
|
||
def resolve(anything) | ||
PropertyMatcher.resolve(anything, @key) | ||
end | ||
|
||
def self.resolve(anything, key) | ||
first, rest = key.split(".", 2) | ||
val = anything.method(first.to_sym).call rescue nil | ||
if rest | ||
return resolve(val, rest) | ||
else | ||
return val.to_s | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.