Skip to content

Commit

Permalink
Improved documentation
Browse files Browse the repository at this point in the history
Signed-off-by: WebFreak001 <janju007@web.de>
  • Loading branch information
WebFreak001 committed Nov 5, 2015
1 parent 5649c72 commit 8cd737c
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 5 deletions.
57 changes: 57 additions & 0 deletions d-linter.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
; Configurue which static analysis checks are enabled
[analysis.config.StaticAnalysisConfig]
; Check variable, class, struct, interface, union, and function names against t
; he Phobos style guide
style_check="false"
; Check for array literals that cause unnecessary allocation
enum_array_literal_check="true"
; Check for poor exception handling practices
exception_check="true"
; Check for use of the deprecated 'delete' keyword
delete_check="true"
; Check for use of the deprecated floating point operators
float_operator_check="true"
; Check number literals for readability
number_style_check="true"
; Checks that opEquals, opCmp, toHash, and toString are either const, immutable
; , or inout.
object_const_check="true"
; Checks for .. expressions where the left side is larger than the right.
backwards_range_check="true"
; Checks for if statements whose 'then' block is the same as the 'else' block
if_else_same_check="true"
; Checks for some problems with constructors
constructor_check="true"
; Checks for unused variables and function parameters
unused_variable_check="false"
; Checks for unused labels
unused_label_check="true"
; Checks for duplicate attributes
duplicate_attribute="true"
; Checks that opEquals and toHash are both defined or neither are defined
opequals_tohash_check="true"
; Checks for subtraction from .length properties
length_subtraction_check="true"
; Checks for methods or properties whose names conflict with built-in propertie
; s
builtin_property_names_check="true"
; Checks for confusing code in inline asm statements
asm_style_check="true"
; Checks for confusing logical operator precedence
logical_precedence_check="true"
; Checks for undocumented public declarations
undocumented_declaration_check="true"
; Checks for poor placement of function attributes
function_attribute_check="true"
; Checks for use of the comma operator
comma_expression_check="true"
; Checks for local imports that are too broad
local_import_check="false"
; Checks for variables that could be declared immutable
could_be_immutable_check="false"
; Checks for redundant expressions in if statements
redundant_if_check="true"
; Checks for redundant parenthesis
redundant_parens_check="true"
; Checks for labels with the same name as variables
label_var_same_name_check="true"
24 changes: 19 additions & 5 deletions source/package.d
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ import core.time;
/// Will ignore the variables and not encode/decode them.
enum schemaIgnore;
/// Custom encode function. `func` is the name of the function which must be present as child.
struct encode { string func; }
struct encode { /++ Function name (needs to be member function) +/ string func; }
/// Custom decode function. `func` is the name of the function which must be present as child.
struct decode { string func; }
struct decode { /++ Function name (needs to be member function) +/ string func; }
/// Encodes the value as binary value. Must be an array with one byte wide elements.
struct binaryType { BsonBinData.Type type = BsonBinData.Type.generic; }
struct binaryType { /++ Type to encode +/ BsonBinData.Type type = BsonBinData.Type.generic; }
/// Custom name for special characters.
struct schemaName { string name; }
struct schemaName { /++ Custom replacement name +/ string name; }

// Mongo Attributes
/// Will create an index with (by default) no flags.
Expand All @@ -35,18 +35,22 @@ enum mongoUnique;
/// Field must be a SchemaDate/BsonDate. You must update the time using collMod.
struct mongoExpire
{
///
this(long seconds)
{
this.seconds = cast(ulong) seconds;
}
///
this(ulong seconds)
{
this.seconds = seconds;
}
///
this(Duration time)
{
seconds = cast(ulong) time.total!"msecs";
}
///
ulong seconds;
}

Expand Down Expand Up @@ -162,7 +166,7 @@ private T bsonToMember(T)(T member, Bson value)
}
}

/// Generated function for generating
/// Generates a Bson document from a struct/class object
Bson toSchemaBson(T)(T obj)
{
Bson data = Bson.emptyObject;
Expand Down Expand Up @@ -220,6 +224,7 @@ Bson toSchemaBson(T)(T obj)
return data;
}

/// Generates a struct/class object from a Bson node
T fromSchemaBson(T)(Bson bson)
{
T obj = T.init;
Expand Down Expand Up @@ -276,11 +281,13 @@ T fromSchemaBson(T)(Bson bson)
return obj;
}

/// Mixin for functions for interacting with Mongo collections.
mixin template MongoSchema()
{
static MongoCollection _schema_collection_;
private BsonObjectID _schema_object_id_;

/// Returns: the _id value (if set by save or find)
@property BsonObjectID bsonID()
{
return _schema_object_id_;
Expand Down Expand Up @@ -363,6 +370,7 @@ mixin template MongoSchema()
}
}

/// Binds a MongoCollection to a Schema. Can only be done once!
void register(T)(MongoCollection collection)
{
T obj = T.init;
Expand Down Expand Up @@ -431,18 +439,22 @@ void register(T)(MongoCollection collection)
final struct SchemaDate
{
public:
///
this(BsonDate date)
{
_time = date.value;
}

///
this(long time)
{
_time = time;
}

///
@property auto time() { return _time; }

///
static Bson toBson(SchemaDate date)
{
if(date._time == -1)
Expand All @@ -455,11 +467,13 @@ public:
}
}

///
static SchemaDate fromBson(Bson bson)
{
return SchemaDate(bson.get!BsonDate.value);
}

/// Magic value setting the date to the current time stamp when serializing.
static SchemaDate now() { return SchemaDate(-1); }

private:
Expand Down

0 comments on commit 8cd737c

Please sign in to comment.