Class: ActiveSet
- Inherits:
-
Object
show all
- Includes:
- Enumerable
- Defined in:
- lib/active_set.rb,
lib/active_set/version.rb,
lib/active_set/instructions/base.rb,
lib/active_set/instructions/entry.rb,
lib/active_set/processors/base_adapter.rb,
lib/active_set/instructions/entry/value.rb,
lib/active_set/processors/base_processor.rb,
lib/active_set/processors/sort_processor.rb,
lib/active_set/instructions/entry/keypath.rb,
lib/active_set/processors/filter_processor.rb,
lib/active_set/processors/paginate_processor.rb,
lib/active_set/processors/transform_processor.rb,
lib/active_set/processors/transform/csv_adapter.rb,
lib/active_set/processors/sort/enumerable_adapter.rb,
lib/active_set/processors/filter/enumerable_adapter.rb,
lib/active_set/processors/sort/active_record_adapter.rb,
lib/active_set/processors/paginate/enumerable_adapter.rb,
lib/active_set/processors/filter/active_record_adapter.rb,
lib/active_set/processors/paginate/active_record_adapter.rb
Defined Under Namespace
Classes: BaseAdapter, BaseProcessor, FilterProcessor, Instructions, PaginateProcessor, SortProcessor, TransformProcessor
Constant Summary
collapse
- VERSION =
'0.5.4'
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(set, instructions: {}, total_count: nil) ⇒ ActiveSet
Returns a new instance of ActiveSet.
15
16
17
18
19
|
# File 'lib/active_set.rb', line 15
def initialize(set, instructions: {}, total_count: nil)
@set = set
@instructions = instructions
@total_count = total_count || @set.count
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
30
31
32
|
# File 'lib/active_set.rb', line 30
def method_missing(method_name, *args, &block)
@set.send(method_name, *args, &block) || super
end
|
Instance Attribute Details
#instructions ⇒ Object
Returns the value of attribute instructions.
13
14
15
|
# File 'lib/active_set.rb', line 13
def instructions
@instructions
end
|
#set ⇒ Object
Returns the value of attribute set.
13
14
15
|
# File 'lib/active_set.rb', line 13
def set
@set
end
|
#total_count ⇒ Object
Returns the value of attribute total_count.
13
14
15
|
# File 'lib/active_set.rb', line 13
def total_count
@total_count
end
|
Instance Method Details
#==(other) ⇒ Object
25
26
27
28
|
# File 'lib/active_set.rb', line 25
def ==(other)
return @set == other unless other.is_a?(ActiveSet)
@set == other.set
end
|
#each(&block) ⇒ Object
21
22
23
|
# File 'lib/active_set.rb', line 21
def each(&block)
@set.each(&block)
end
|
#filter(instructions) ⇒ Object
38
39
40
41
|
# File 'lib/active_set.rb', line 38
def filter(instructions)
filterer = FilterProcessor.new(@set, instructions)
new_active_set(filterer.process, :filter, instructions)
end
|
#paginate(instructions) ⇒ Object
48
49
50
51
52
53
|
# File 'lib/active_set.rb', line 48
def paginate(instructions)
paginater = PaginateProcessor.new(@set, instructions)
full_instructions = instructions.reverse_merge(page: paginater.send(:page_number),
size: paginater.send(:page_size))
new_active_set(paginater.process, :paginate, full_instructions)
end
|
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
34
35
36
|
# File 'lib/active_set.rb', line 34
def respond_to_missing?(method_name, include_private = false)
@set.respond_to?(method_name) || super
end
|
#sort(instructions) ⇒ Object
43
44
45
46
|
# File 'lib/active_set.rb', line 43
def sort(instructions)
sorter = SortProcessor.new(@set, instructions)
new_active_set(sorter.process, :sort, instructions)
end
|
55
56
57
58
|
# File 'lib/active_set.rb', line 55
def transform(instructions)
transformer = TransformProcessor.new(@set, instructions)
transformer.process
end
|