Class: BucketMaker::SeriesMaker
- Inherits:
-
Object
- Object
- BucketMaker::SeriesMaker
- Includes:
- Singleton
- Defined in:
- lib/bucket_maker/series_maker.rb
Overview
Singleton which holds all information regarding the series, buckets and groups
Constant Summary collapse
- BUCKET_ROOT =
'series'
Instance Attribute Summary collapse
-
#configuration ⇒ Object
readonly
Returns the value of attribute configuration.
-
#series ⇒ Object
Returns the value of attribute series.
Instance Method Summary collapse
-
#bucketable?(bucketable, series_name, bucket_name, group_name) ⇒ Boolean
Check if a Bucketable Object conform to the pre-conditions.
-
#bucketize(series_name, bucket_name) ⇒ String
Get a random group for the bucket in a series.
-
#configured? ⇒ Boolean
Check if the SeriesMaker is configured.
-
#for_each_series_with_bucketable ⇒ Object
Iterator for each series to be run on a Bucketable instance Expects a block parameter to be passed.
-
#has_bucket_in_series?(series_name, bucket_name) ⇒ Boolean
Check if the bucket exist in the series.
-
#has_group_in_bucket_in_series?(series_name, bucket_name, group_name) ⇒ Boolean
Check if the group exists in the bucket in the series.
-
#has_series?(series_name) ⇒ Boolean
Check if the series exist.
-
#key_for_series(bucketable, series_name, bucket_name) ⇒ String
Get the key for the combination.
-
#make!(config) ⇒ Object
Set the class variables with configuration details.
-
#series_with_name(series_name) ⇒ BucketMaker::Series
Get the Series object when given the series_name.
Instance Attribute Details
#configuration ⇒ Object (readonly)
Returns the value of attribute configuration.
14 15 16 |
# File 'lib/bucket_maker/series_maker.rb', line 14 def configuration @configuration end |
#series ⇒ Object
Returns the value of attribute series.
12 13 14 |
# File 'lib/bucket_maker/series_maker.rb', line 12 def series @series end |
Instance Method Details
#bucketable?(bucketable, series_name, bucket_name, group_name) ⇒ Boolean
Check if a Bucketable Object conform to the pre-conditions
125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/bucket_maker/series_maker.rb', line 125 def bucketable?(bucketable, series_name, bucket_name, group_name) if bucketable.has_attribute?(:created_at) && has_group_in_bucket_in_series?(series_name, bucket_name, group_name) series_with_name(series_name).bucket_with_name(bucket_name).is_bucketable?(bucketable) || series_with_name(series_name).is_bucketable?(bucketable) rescue false else false end end |
#bucketize(series_name, bucket_name) ⇒ String
Get a random group for the bucket in a series
113 114 115 |
# File 'lib/bucket_maker/series_maker.rb', line 113 def bucketize(series_name, bucket_name) series_with_name(series_name).bucket_with_name(bucket_name).random_group rescue nil end |
#configured? ⇒ Boolean
Check if the SeriesMaker is configured
41 42 43 |
# File 'lib/bucket_maker/series_maker.rb', line 41 def configured? @configuration != nil end |
#for_each_series_with_bucketable ⇒ Object
Iterator for each series to be run on a Bucketable instance Expects a block parameter to be passed
48 49 50 51 52 53 54 |
# File 'lib/bucket_maker/series_maker.rb', line 48 def for_each_series_with_bucketable @series.map do |series_name, series| series.each_bucket do |bucket_name, bucket| yield self, series_name, bucket_name end end.inject(true) {|result, value| result && value } if block_given? end |
#has_bucket_in_series?(series_name, bucket_name) ⇒ Boolean
Check if the bucket exist in the series
80 81 82 |
# File 'lib/bucket_maker/series_maker.rb', line 80 def has_bucket_in_series?(series_name, bucket_name) has_series?(series_name) && series_with_name(series_name).has_bucket?(bucket_name) rescue false end |
#has_group_in_bucket_in_series?(series_name, bucket_name, group_name) ⇒ Boolean
Check if the group exists in the bucket in the series
91 92 93 94 |
# File 'lib/bucket_maker/series_maker.rb', line 91 def has_group_in_bucket_in_series?(series_name, bucket_name, group_name) has_bucket_in_series?(series_name, bucket_name) && series_with_name(series_name).bucket_with_name(bucket_name).has_group?(group_name) rescue false end |
#has_series?(series_name) ⇒ Boolean
Check if the series exist
70 71 72 |
# File 'lib/bucket_maker/series_maker.rb', line 70 def has_series?(series_name) @series[series_name.to_sym] != nil rescue false end |
#key_for_series(bucketable, series_name, bucket_name) ⇒ String
Get the key for the combination
103 104 105 |
# File 'lib/bucket_maker/series_maker.rb', line 103 def key_for_series(bucketable, series_name, bucket_name) "bucket_maker:#{bucketable.class.to_s.underscore}_#{bucketable.id}:#{series_name.to_s}:#{bucket_name.to_s}" if bucketable && bucketable.id rescue nil end |
#make!(config) ⇒ Object
Set the class variables with configuration details
22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/bucket_maker/series_maker.rb', line 22 def make!(config) @series = [] absolute_config_path = Rails.root + config if File.exists?(absolute_config_path) @configuration = YAML.load_file(absolute_config_path) @series = @configuration[BUCKET_ROOT].inject({}) do |result, (series_name, )| result[series_name.to_sym] = BucketMaker::Series.new(series_name, ) result end if @configuration && @configuration[BUCKET_ROOT] end end |
#series_with_name(series_name) ⇒ BucketMaker::Series
Get the Series object when given the series_name
61 62 63 |
# File 'lib/bucket_maker/series_maker.rb', line 61 def series_with_name(series_name) @series[series_name.to_sym] if series_name end |