Class: Grut::Statement
- Inherits:
-
Object
- Object
- Grut::Statement
- Includes:
- Concerns::DBTables
- Defined in:
- lib/grut/statement.rb
Defined Under Namespace
Classes: Entry
Instance Method Summary collapse
- #all(role: nil, permission: nil, contract: {}) ⇒ Object
-
#initialize(user) ⇒ Statement
constructor
A new instance of Statement.
Constructor Details
#initialize(user) ⇒ Statement
Returns a new instance of Statement.
11 12 13 |
# File 'lib/grut/statement.rb', line 11 def initialize(user) @user = user end |
Instance Method Details
#all(role: nil, permission: nil, contract: {}) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/grut/statement.rb', line 15 def all(role: nil, permission: nil, contract: {}) = .to_s if role = role.to_s if role contract = Asset.stringify_hash(contract) = ? 'and p.name = :permission' : '' role_condition = role ? 'and r.name = :role' : '' contract_condition = contract.any? ? "and #{Asset.contract_sql_condition(contract)}" : '' args = Asset.sanitize_contract_hash(contract).merge(user_id: @user.id, role: role, permission: ) DB.conn[<<-SQL, args].map { |args| Entry.from_hash(args) } select r.name as role, p.name as permission, pp.key as contract_key, pp.value as contract_value from #{roles_table} r join #{} p on p.role_id = r.id #{} join #{} pp on pp.permission_id = p.id #{contract_condition} where r.user_id = :user_id #{role_condition} SQL end |