Module: Kilt
- Defined in:
- lib/kilt.rb,
lib/kilt/form.rb,
lib/kilt/utils.rb,
lib/kilt/engine.rb,
lib/kilt/object.rb,
lib/kilt/upload.rb,
lib/kilt/slugger.rb,
lib/kilt/upload/s3.rb,
lib/kilt/exceptions.rb,
lib/kilt/formatting.rb,
lib/kilt/upload/local.rb,
lib/kilt/db/active_record.rb,
lib/kilt/object_collection.rb,
app/controllers/kilt/kilt_controller.rb,
lib/generators/kilt/object_generator.rb,
lib/generators/kilt/backend_generator.rb,
lib/generators/kilt/install_generator.rb
Defined Under Namespace
Modules: DB, Form, Formatting, Generators, Slugger, Upload Classes: CantConnectToDatabaseError, CantSetupDatabaseError, ConfigError, DatabaseError, Engine, KiltController, NoConfigError, NoDatabaseConfigError, Object, ObjectCollection, Utils
Class Method Summary collapse
-
.all_used_fields ⇒ Object
Get every field type used Returns: Array of strings Example: Kilt.all_used_fields.
-
.create(object) ⇒ Object
Create an object Returns: boolean Example: Kilt.create(object).
-
.delete(slug) ⇒ Object
Delete an object Returns: boolean Example: Kilt.delete(‘some-object’).
-
.get(slug) ⇒ Object
Get the content for a specific object Returns: Kilt::Object instance Example: Kilt.object(‘big-event’).
-
.get_collection(object_type) ⇒ Object
Get a list of objects Returns: array of hashes Example: Kilt.objects(‘events’) Used directly or via method_missing.
-
.method_missing(method, *args) ⇒ Object
Auto-generated endpoints.
-
.types ⇒ Object
Get the list of types Returns: array of type names Example: Kilt.types.
-
.update(slug, object) ⇒ Object
Update an object Returns: boolean Example: Kilt.update(object).
Class Method Details
.all_used_fields ⇒ Object
Get every field type used Returns: Array of strings Example: Kilt.all_used_fields
84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/kilt.rb', line 84 def self.all_used_fields used_field_types = Kilt.config[:objects].map do |object| object.map do |config| begin config[:fields].map { |_, v| v } rescue nil end end end.flatten used_field_types.select { |x| x }.group_by { |x| x }.map { |x| x[0] } end |
.create(object) ⇒ Object
Create an object Returns: boolean Example: Kilt.create(object)
37 38 39 40 41 42 43 44 |
# File 'lib/kilt.rb', line 37 def self.create(object) object['created_at'] = object['updated_at'] = Time.now object['unique_id'] = "#{(Time.now.to_f * 1000).to_i}" object['type'] = object.instance_eval { @type } object['slug'] = Slugger.slug_for object Utils.database.create object end |
.delete(slug) ⇒ Object
Delete an object Returns: boolean Example: Kilt.delete(‘some-object’)
59 60 61 |
# File 'lib/kilt.rb', line 59 def self.delete(slug) Utils.database.delete slug end |
.get(slug) ⇒ Object
Get the content for a specific object Returns: Kilt::Object instance Example: Kilt.object(‘big-event’)
66 67 68 69 70 |
# File 'lib/kilt.rb', line 66 def self.get(slug) result = Utils.database.find(slug) result ? Kilt::Object.new(result['type'], result) : nil end |
.get_collection(object_type) ⇒ Object
Get a list of objects Returns: array of hashes Example: Kilt.objects(‘events’) Used directly or via method_missing
76 77 78 79 |
# File 'lib/kilt.rb', line 76 def self.get_collection(object_type) results = Utils.database.find_all_by_type object_type Kilt::ObjectCollection.new results end |
.method_missing(method, *args) ⇒ Object
Auto-generated endpoints
11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/kilt.rb', line 11 def self.method_missing(method, *args) begin if Utils.is_singular? method.to_s # Get the configuration for a type # Example: Kilt.event Kilt.config.objects[method] else # Get a list of objects # Example: Kilt.events Kilt.get_collection method.to_s end end end |