Giter Site home page Giter Site logo

mboya / engie-cc Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 23 KB

Your task is to implement a Concern (or any comparable pattern) that can be re-used in multiple models (i.e. in the ones given above) to encapsulate the logic necessary to store custom attributes

Dockerfile 5.73% Ruby 93.57% Shell 0.70%

engie-cc's Introduction

Engie Code Challenge

This Code Challenge is to show the implementation on a concern within a rails app that multiple models can use in order to store custom attributes without having to do a DB change to add that attribute.

How to:

Clone app

git clone [email protected]:mboya/engie-cc.git

Setup the app locally

create and setup the DB - this is running SQLite at the moment

rake db:create db:migrate

Test

To check if the app has good/working tests, run:

rails test

to run a specific file test

rails test test/models/customer_test.rb

to run a specific file test block

rails test test/models/customer_test.rb:17

Test out on console

rails console

app has been setup up so that once the above code has been run it will automatically connect to the defined database

>> Customer.create({name: 'customer', phone_number: '555-555-555'})
>> customer = _
>> customer.set_custom_attribute(:email, '[email protected]')
>> customer.save

The above quesry will be able to create a customer and add a custom attribute and value to the records. Other functions can be run against the same record to manipulate and pull data from it

fetch

>> customer = Customer.find 1
>> customer.get_custom_attribute(:email)

remove

>> customer = Customer.find 1
>> customer.remove_custom_attribute(:email)

to view all the keys/custom attributes available against a specific record

>> customer = Custome.find 1
>> customer.custom_attributes_keys?

and also to check if a key exists within a record

>> customer = Customer.find 1
>> customer.custom_attribute?(:email)

and for search, this can work across multiple models that are linked to the concern

>> Customer.find_by_custom_attribute(:email, '[email protected]')

engie-cc's People

Contributors

mboya avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.