Class: Warrant::Feature
- Includes:
- WarrantObject
- Defined in:
- lib/warrant/models/feature.rb
Constant Summary collapse
- OBJECT_TYPE =
"feature"
Instance Attribute Summary
Attributes inherited from Object
#created_at, #meta, #object_id, #object_type
Class Method Summary collapse
-
.assign_to_pricing_tier(pricing_tier_id, feature_id, relation: "member", options: {}) ⇒ Warrant
Assign a feature to a pricing tier.
-
.assign_to_tenant(tenant_id, feature_id, relation: "member", options: {}) ⇒ Warrant
Assign a feature to a tenant.
-
.assign_to_user(user_id, feature_id, relation: "member", options: {}) ⇒ Warrant
Assign a feature to a user.
-
.create(params = {}, options = {}) ⇒ Feature
Creates a feature with the given parameters.
-
.delete(feature_id, options = {}) ⇒ nil
Deletes a feature with given feature id.
-
.get(feature_id, options = {}) ⇒ Feature
Get a feature with the given feature_id.
-
.list(filters = {}, options = {}) ⇒ Array<Feature>
Lists all features for your organization.
-
.list_for_pricing_tier(pricing_tier_id, filters = {}, options = {}) ⇒ Array<Feature>
List features for pricing tier.
-
.list_for_tenant(tenant_id, filters = {}, options = {}) ⇒ Array<Feature>
List features for tenant.
-
.list_for_user(user_id, filters = {}, options = {}) ⇒ Array<Feature>
List features for user.
-
.remove_from_pricing_tier(pricing_tier_id, feature_id, relation: "member", options: {}) ⇒ nil
Remove a feature from a pricing tier.
-
.remove_from_tenant(tenant_id, feature_id, relation: "member", options: {}) ⇒ nil
Remove a feature from a tenant.
-
.remove_from_user(user_id, feature_id, relation: "member", options: {}) ⇒ nil
Remove a feature from a user.
-
.update(feature_id, meta, options = {}) ⇒ Feature
Updates a feature with the given feature_id and params.
Instance Method Summary collapse
-
#update(meta, options = {}) ⇒ Feature
Updates a feature with the given params.
- #warrant_object_id ⇒ Object
- #warrant_object_type ⇒ Object
Methods inherited from Object
Class Method Details
.assign_to_pricing_tier(pricing_tier_id, feature_id, relation: "member", options: {}) ⇒ Warrant
Assign a feature to a pricing tier
284 285 286 |
# File 'lib/warrant/models/feature.rb', line 284 def self.assign_to_pricing_tier(pricing_tier_id, feature_id, relation: "member", options: {}) Warrant.create({ object_type: Feature::OBJECT_TYPE, object_id: feature_id }, relation, { object_type: PricingTier::OBJECT_TYPE, object_id: pricing_tier_id }, nil, ) end |
.assign_to_tenant(tenant_id, feature_id, relation: "member", options: {}) ⇒ Warrant
Assign a feature to a tenant
168 169 170 |
# File 'lib/warrant/models/feature.rb', line 168 def self.assign_to_tenant(tenant_id, feature_id, relation: "member", options: {}) Warrant.create({ object_type: Feature::OBJECT_TYPE, object_id: feature_id }, relation, { object_type: Tenant::OBJECT_TYPE, object_id: tenant_id }, nil, ) end |
.assign_to_user(user_id, feature_id, relation: "member", options: {}) ⇒ Warrant
Assign a feature to a user
226 227 228 |
# File 'lib/warrant/models/feature.rb', line 226 def self.assign_to_user(user_id, feature_id, relation: "member", options: {}) Warrant.create({ object_type: Feature::OBJECT_TYPE, object_id: feature_id }, relation, { object_type: User::OBJECT_TYPE, object_id: user_id }, nil, ) end |
.create(params = {}, options = {}) ⇒ Feature
Creates a feature with the given parameters
30 31 32 33 |
# File 'lib/warrant/models/feature.rb', line 30 def self.create(params = {}, = {}) object = Object.create({ object_type: OBJECT_TYPE, object_id: params[:feature_id], meta: params[:meta] }, ) return Feature.new(object.object_id, object., object.created_at) end |
.delete(feature_id, options = {}) ⇒ nil
Deletes a feature with given feature id
48 49 50 |
# File 'lib/warrant/models/feature.rb', line 48 def self.delete(feature_id, = {}) return Object.delete(OBJECT_TYPE, feature_id, ) end |
.get(feature_id, options = {}) ⇒ Feature
Get a feature with the given feature_id
87 88 89 90 |
# File 'lib/warrant/models/feature.rb', line 87 def self.get(feature_id, = {}) object = Object.get(OBJECT_TYPE, feature_id, ) return Feature.new(object.object_id, object., object.created_at) end |
.list(filters = {}, options = {}) ⇒ Array<Feature>
Lists all features for your organization
70 71 72 73 74 75 |
# File 'lib/warrant/models/feature.rb', line 70 def self.list(filters = {}, = {}) filters.merge({ object_type: OBJECT_TYPE }) list_response = Object.list(filters, ) features = list_response.results.map{ |object| Feature.new(object.object_id, object., object.created_at)} return ListResponse.new(features, list_response.prev_cursor, list_response.next_cursor) end |
.list_for_pricing_tier(pricing_tier_id, filters = {}, options = {}) ⇒ Array<Feature>
List features for pricing tier
265 266 267 268 269 |
# File 'lib/warrant/models/feature.rb', line 265 def self.list_for_pricing_tier(pricing_tier_id, filters = {}, = {}) query_response = Warrant.query("select feature where pricing-tier:#{pricing_tier_id} is *", filters: filters, options: ) features = query_response.results.map{ |result| Feature.new(result.object_id, result.) } return ListResponse.new(features, query_response.prev_cursor, query_response.next_cursor) end |
.list_for_tenant(tenant_id, filters = {}, options = {}) ⇒ Array<Feature>
List features for tenant
149 150 151 152 153 |
# File 'lib/warrant/models/feature.rb', line 149 def self.list_for_tenant(tenant_id, filters = {}, = {}) query_response = Warrant.query("select feature where tenant:#{tenant_id} is *", filters: filters, options: ) features = query_response.results.map{ |result| Feature.new(result.object_id, result.) } return ListResponse.new(features, query_response.prev_cursor, query_response.next_cursor) end |
.list_for_user(user_id, filters = {}, options = {}) ⇒ Array<Feature>
List features for user
207 208 209 210 211 |
# File 'lib/warrant/models/feature.rb', line 207 def self.list_for_user(user_id, filters = {}, = {}) query_response = Warrant.query("select feature where user:#{user_id} is *", filters: filters, options: ) features = query_response.results.map{ |result| Feature.new(result.object_id, result.) } return ListResponse.new(features, query_response.prev_cursor, query_response.next_cursor) end |
.remove_from_pricing_tier(pricing_tier_id, feature_id, relation: "member", options: {}) ⇒ nil
Remove a feature from a pricing tier
301 302 303 |
# File 'lib/warrant/models/feature.rb', line 301 def self.remove_from_pricing_tier(pricing_tier_id, feature_id, relation: "member", options: {}) Warrant.delete({ object_type: Feature::OBJECT_TYPE, object_id: feature_id }, relation, { object_type: PricingTier::OBJECT_TYPE, object_id: pricing_tier_id }, nil, ) end |
.remove_from_tenant(tenant_id, feature_id, relation: "member", options: {}) ⇒ nil
Remove a feature from a tenant
185 186 187 |
# File 'lib/warrant/models/feature.rb', line 185 def self.remove_from_tenant(tenant_id, feature_id, relation: "member", options: {}) Warrant.delete({ object_type: Feature::OBJECT_TYPE, object_id: feature_id }, relation, { object_type: Tenant::OBJECT_TYPE, object_id: tenant_id }, nil, ) end |
.remove_from_user(user_id, feature_id, relation: "member", options: {}) ⇒ nil
Remove a feature from a user
243 244 245 |
# File 'lib/warrant/models/feature.rb', line 243 def self.remove_from_user(user_id, feature_id, relation: "member", options: {}) Warrant.delete({ object_type: Feature::OBJECT_TYPE, object_id: feature_id }, relation, { object_type: User::OBJECT_TYPE, object_id: user_id }, nil, ) end |
.update(feature_id, meta, options = {}) ⇒ Feature
Updates a feature with the given feature_id and params
107 108 109 110 |
# File 'lib/warrant/models/feature.rb', line 107 def self.update(feature_id, , = {}) object = Object.update(OBJECT_TYPE, feature_id, , ) return Feature.new(object.object_id, object., object.created_at) end |
Instance Method Details
#update(meta, options = {}) ⇒ Feature
Updates a feature with the given params
127 128 129 |
# File 'lib/warrant/models/feature.rb', line 127 def update(, = {}) return Feature.update(feature_id, ) end |
#warrant_object_id ⇒ Object
309 310 311 |
# File 'lib/warrant/models/feature.rb', line 309 def warrant_object_id feature_id end |
#warrant_object_type ⇒ Object
305 306 307 |
# File 'lib/warrant/models/feature.rb', line 305 def warrant_object_type "feature" end |