Class: Moderation
- Inherits:
-
Object
- Object
- Moderation
- Defined in:
- lib/moderation.rb,
lib/moderation/storage.rb,
lib/moderation/version.rb,
lib/moderation/storage/redis.rb,
lib/moderation/storage/in_memory.rb
Defined Under Namespace
Classes: Storage
Constant Summary collapse
- DEFAULT_LIMIT =
25- VERSION =
"0.0.3"
Instance Attribute Summary collapse
-
#construct_with ⇒ Object
readonly
Returns the value of attribute construct_with.
-
#constructor ⇒ Object
readonly
Returns the value of attribute constructor.
-
#limit ⇒ Object
readonly
Returns the value of attribute limit.
-
#storage ⇒ Object
readonly
Returns the value of attribute storage.
Instance Method Summary collapse
- #all(options = {}) ⇒ Object
-
#initialize(options = {}) ⇒ Moderation
constructor
A new instance of Moderation.
- #insert(item) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Moderation
Returns a new instance of Moderation.
9 10 11 12 13 14 15 |
# File 'lib/moderation.rb', line 9 def initialize( = {}) @constructor = [:constructor] @construct_with = [:construct_with] @limit = .fetch(:limit, DEFAULT_LIMIT) @storage = .fetch(:storage, Storage::InMemory.new) @storage.limit = @limit end |
Instance Attribute Details
#construct_with ⇒ Object (readonly)
Returns the value of attribute construct_with.
5 6 7 |
# File 'lib/moderation.rb', line 5 def construct_with @construct_with end |
#constructor ⇒ Object (readonly)
Returns the value of attribute constructor.
5 6 7 |
# File 'lib/moderation.rb', line 5 def constructor @constructor end |
#limit ⇒ Object (readonly)
Returns the value of attribute limit.
5 6 7 |
# File 'lib/moderation.rb', line 5 def limit @limit end |
#storage ⇒ Object (readonly)
Returns the value of attribute storage.
5 6 7 |
# File 'lib/moderation.rb', line 5 def storage @storage end |
Instance Method Details
#all(options = {}) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/moderation.rb', line 21 def all( = {}) fetch_limit = .fetch(:limit, limit) storage.all(limit: fetch_limit).map do |stored_item| if using_custom_constructor? constructor.send(construct_with, stored_item) elsif using_constructor? data = MultiJson.load(stored_item, :symbolize_keys => true) constructor.new(data) else MultiJson.load(stored_item, :symbolize_keys => true) end end end |
#insert(item) ⇒ Object
17 18 19 |
# File 'lib/moderation.rb', line 17 def insert(item) storage.insert(MultiJson.dump(item)) end |