Class: ActiveSet

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/active_set.rb,
lib/active_set/sorting/operation.rb,
lib/active_set/column_instruction.rb,
lib/active_set/exporting/operation.rb,
lib/active_set/filtering/constants.rb,
lib/active_set/filtering/operation.rb,
lib/active_set/paginating/operation.rb,
lib/active_set/attribute_instruction.rb,
lib/active_set/exporting/csv_strategy.rb,
lib/active_set/enumerable_set_instruction.rb,
lib/active_set/sorting/enumerable_strategy.rb,
lib/active_set/active_record_set_instruction.rb,
lib/active_set/filtering/enumerable/strategy.rb,
lib/active_set/filtering/enumerable/operators.rb,
lib/active_set/paginating/enumerable_strategy.rb,
lib/active_set/sorting/active_record_strategy.rb,
lib/active_set/filtering/active_record/strategy.rb,
lib/active_set/filtering/active_record/operators.rb,
lib/active_set/paginating/active_record_strategy.rb,
lib/active_set/filtering/active_record/query_value.rb,
lib/active_set/filtering/active_record/query_column.rb,
lib/active_set/filtering/enumerable/set_instruction.rb,
lib/active_set/filtering/active_record/set_instruction.rb

Defined Under Namespace

Modules: Exporting, Filtering, Paginating, Sorting Classes: ActiveRecordSetInstruction, AttributeInstruction, ColumnInstruction, Configuration, EnumerableSetInstruction

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(set, view: nil, instructions: {}) ⇒ ActiveSet

Returns a new instance of ActiveSet.



40
41
42
43
44
# File 'lib/active_set.rb', line 40

def initialize(set, view: nil, instructions: {})
  @set = set
  @view = view || set
  @instructions = instructions
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object



61
62
63
64
65
# File 'lib/active_set.rb', line 61

def method_missing(method_name, *args, &block)
  return @view.send(method_name, *args, &block) if @view.respond_to?(method_name)

  super
end

Class Attribute Details

.configurationObject



26
27
28
# File 'lib/active_set.rb', line 26

def self.configuration
  @configuration ||= Configuration.new
end

Instance Attribute Details

#instructionsObject (readonly)

Returns the value of attribute instructions.



38
39
40
# File 'lib/active_set.rb', line 38

def instructions
  @instructions
end

#setObject (readonly)

Returns the value of attribute set.



38
39
40
# File 'lib/active_set.rb', line 38

def set
  @set
end

#viewObject (readonly)

Returns the value of attribute view.



38
39
40
# File 'lib/active_set.rb', line 38

def view
  @view
end

Class Method Details

.configure {|configuration| ... } ⇒ Object

Yields:



30
31
32
# File 'lib/active_set.rb', line 30

def self.configure
  yield(configuration)
end

.reset_configurationObject



34
35
36
# File 'lib/active_set.rb', line 34

def self.reset_configuration
  @configuration = Configuration.new
end

Instance Method Details

#==(other) ⇒ Object



55
56
57
58
59
# File 'lib/active_set.rb', line 55

def ==(other)
  return @view == other unless other.is_a?(ActiveSet)

  @view == other.view
end

#each(&block) ⇒ Object



46
47
48
# File 'lib/active_set.rb', line 46

def each(&block)
  @view.each(&block)
end

#export(instructions_hash) ⇒ Object



87
88
89
90
# File 'lib/active_set.rb', line 87

def export(instructions_hash)
  exporter = Exporting::Operation.new(@view, instructions_hash)
  exporter.execute
end

#filter(instructions_hash) ⇒ Object

:nocov:



72
73
74
75
# File 'lib/active_set.rb', line 72

def filter(instructions_hash)
  filterer = Filtering::Operation.new(@view, instructions_hash)
  reinitialize(filterer.execute, :filter, filterer.operation_instructions)
end

#inspectObject

:nocov:



51
52
53
# File 'lib/active_set.rb', line 51

def inspect
  "#<ActiveSet:#{object_id} @instructions=#{@instructions.inspect}>"
end

#paginate(instructions_hash) ⇒ Object



82
83
84
85
# File 'lib/active_set.rb', line 82

def paginate(instructions_hash)
  paginater = Paginating::Operation.new(@view, instructions_hash)
  reinitialize(paginater.execute, :paginate, paginater.operation_instructions)
end

#respond_to_missing?(method_name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


67
68
69
# File 'lib/active_set.rb', line 67

def respond_to_missing?(method_name, include_private = false)
  @view.respond_to?(method_name) || super
end

#sort(instructions_hash) ⇒ Object



77
78
79
80
# File 'lib/active_set.rb', line 77

def sort(instructions_hash)
  sorter = Sorting::Operation.new(@view, instructions_hash)
  reinitialize(sorter.execute, :sort, sorter.operation_instructions)
end