Class: DesignManagement::VersionsFinder

Inherits:
Object
  • Object
show all
Defined in:
app/finders/design_management/versions_finder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(design_or_collection, current_user, params = {}) ⇒ VersionsFinder

The `design_or_collection` argument should be either a:

  • DesignManagement::Design, or

  • DesignManagement::DesignCollection

The object will have `#versions` called on it to set up the initial scope of the versions.

valid params:

- earlier_or_equal_to: Version
- sha: String
- version_id: Integer

20
21
22
23
24
# File 'app/finders/design_management/versions_finder.rb', line 20

def initialize(design_or_collection, current_user, params = {})
  @design_or_collection = design_or_collection
  @current_user = current_user
  @params = params
end

Instance Attribute Details

#current_userObject (readonly)

Returns the value of attribute current_user


5
6
7
# File 'app/finders/design_management/versions_finder.rb', line 5

def current_user
  @current_user
end

#design_or_collectionObject (readonly)

Returns the value of attribute design_or_collection


5
6
7
# File 'app/finders/design_management/versions_finder.rb', line 5

def design_or_collection
  @design_or_collection
end

#paramsObject (readonly)

Returns the value of attribute params


5
6
7
# File 'app/finders/design_management/versions_finder.rb', line 5

def params
  @params
end

Instance Method Details

#executeObject


26
27
28
29
30
31
32
33
34
35
36
# File 'app/finders/design_management/versions_finder.rb', line 26

def execute
  unless Ability.allowed?(current_user, :read_design, design_or_collection)
    return ::DesignManagement::Version.none
  end

  items = design_or_collection.versions
  items = by_earlier_or_equal_to(items)
  items = by_sha(items)
  items = by_version_id(items)
  items.ordered
end