Module: Ronin::Model::HasLicense::ClassMethods

Defined in:
lib/ronin/model/has_license.rb

Overview

Class methods that are added when Ronin::Model::HasLicense is included into a model.

Instance Method Summary collapse

Instance Method Details

#licensed_under(license) ⇒ Array<Model>

Finds all models associated with a given license.

Examples:

Query using a predefined License resource.

LicensedModel.licensed_under(License.mit)
# => [#<Ronin::LicensedModel: ...>, ...]

Query using the name of a predefined License.

LicensedModel.licensed_under(:cc_by_nc)
# => [#<Ronin::LicensedModel: ...>, ...]

Query using the name of a License.

LicensedModel.licensed_under('GPL-2')
# => [#<Ronin::LicensedModel: ...>, ...]

Parameters:

  • license (License, Symbol, #to_s)

    The license which models are associated with.

Returns:

  • (Array<Model>)

    The models associated with a given license.

Since:

  • 1.0.0



79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/ronin/model/has_license.rb', line 79

def licensed_under(license)
  conditions = case license
               when License
                 {:license => license}
               when Symbol
                 {:license => License.predefined_resource(license)}
               else
                 {'license.name' => license.to_s}
               end

  all(conditions)
end