Module: Democritus

Defined in:
lib/democritus.rb,
lib/democritus/version.rb,
lib/democritus/class_builder.rb,
lib/democritus/class_builder/command.rb,
lib/democritus/class_builder/commands.rb,
lib/democritus/from_json_class_builder.rb,
lib/democritus/class_builder/commands/attribute.rb,
lib/democritus/class_builder/commands/attributes.rb

Overview

Compose objects by leveraging a DSL for class creation. Yes, we can write code that conforms to interfaces, but in my experience, as the Ruby object ecosystem has grown, so too has the needs for understanding the galaxy of objects.

Defined Under Namespace

Modules: Commands, DemocritusObjectTag Classes: ClassBuilder, FromJsonClassBuilder

Constant Summary collapse

VERSION =

Democritus is striving to adhere to semantic versioning.

See Also:

  • Democritus.semversemver.org
"0.2.1"

Class Method Summary collapse

Class Method Details

.build {|Democritus::ClassBuilder| ... } ⇒ Object

Responsible for building a class based on atomic components.

Examples:

NamedPerson = Democritus.build do |builder|
  builder.attributes do
    attribute(name: :given_name)
    attribute(name: :surname)
  end
end
NamedPerson.new(given_name: 'Farrokh', surname: 'Bulsara')

Yields:

Returns:

  • Class

See Also:

  • Demcoritus::ClassBuilder

Since:

  • 0.1.0



28
29
30
31
32
# File 'lib/democritus.rb', line 28

def self.build(&configuration_block)
  builder = ClassBuilder.new
  builder.customize(&configuration_block)
  builder.generate_class
end

.build_from_json(json) ⇒ Object

Responsible for building a class based on the given JSON object.

Parameters:

  • A (String)

    “well-formed” JSON document

Returns:

  • Class

    NamedPerson = Democritus.build_from_json(%{

    "#attributes": {
      "#attribute": [{ "name": "given_name" }, { "name": "surname"}]
    }
    

    }) NamedPerson.new(given_name: ‘Farrokh’, surname: ‘Bulsara’)

See Also:

  • for details on "well-formed"

Since:

  • 0.2.0



50
51
52
53
# File 'lib/democritus.rb', line 50

def self.build_from_json(json)
  builder = FromJsonClassBuilder.new(json)
  builder.generate_class
end