• Stars
    star
    173
  • Rank 219,266 (Top 5 %)
  • Language
    Ruby
  • Created about 12 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Object initializer from attributes hash

anima

CI

Simple library to declare read only attributes on value-objects that are initialized via attributes hash.

Installation

Install the gem anima via your preferred method.

Examples

require 'anima'

# Definition
class Person
  include Anima.new(:salutation, :firstname, :lastname)
end

# Every day operation
a = Person.new(
  salutation: 'Mr',
  firstname:  'Markus',
  lastname:   'Schirp'
)

# Returns expected values
a.salutation # => "Mr"
a.firstname  # => "Markus"
a.lastname   # => "Schirp"
a.frozen?    # => false

b = Person.new(
  salutation: 'Mr',
  firstname:  'John',
  lastname:   'Doe'
)

c = Person.new(
  salutation: 'Mr',
  firstname:  'Markus',
  lastname:   'Schirp'
)

# Equality based on attributes
a == b      # => false
a.eql?(b)   # => false
a.equal?(b) # => false

a == c      # => true
a.eql?(c)   # => true
a.equal?(c) # => false

# Functional-style updates
d = b.with(
  salutation: 'Mrs',
  firstname:  'Sue',
)

# It returns copies, no inplace modification
d.equal?(b) # => false

# Hash representation
d.to_h # => { salutation: 'Mrs', firstname: 'Sue', lastname: 'Doe' }

# Disallows initialization with incompatible attributes

Person.new(
  # :saluatation key missing
  "firstname" => "Markus", # does NOT coerce this by intention
  :lastname   => "Schirp"
) # raises Anima::Error with message "Person attributes missing: [:salutation, :firstname], unknown: ["firstname"]

Credits

Contributing

  • Fork the project.
  • Make your feature addition or bug fix.
  • Add tests for it. This is important so I don't break it in a future version unintentionally.
  • Commit, do not mess with Rakefile or version (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
  • Send me a pull request. Bonus points for topic branches.

License

Copyright (c) 2013 Markus Schirp

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

More Repositories

1

mutant

Automated code reviews via mutation testing - semantic code coverage.
Ruby
1,947
star
2

unparser

Turn Ruby AST into semantically equivalent Ruby source
Ruby
309
star
3

stratosphere

Haskell EDSL and type-checker for AWS CloudFormation templates
Haskell
162
star
4

vanguard

External validations for ruby objects
Ruby
120
star
5

concord

Mixin to ease compositions in ruby
Ruby
112
star
6

devtools

The rake ci task!
Ruby
64
star
7

inflecto

Inflector for ruby
46
star
8

auom

Algebra with units of measurement.
Ruby
27
star
9

axiom-mongo-adapter

An MongoDB adapter for Axiom
Ruby
11
star
10

esearch

A ruby driver for elasticsearch that is ONLY A DRIVER.
Ruby
11
star
11

axiom-arango-adapter

An ArangoDB adapter for Axiom
Ruby
8
star
12

mhs

Haskell tooling megarepo
Haskell
8
star
13

axiom-elasticsearch-adapter

An Elasticsearch adapter for Axiom.
Ruby
8
star
14

mprelude-rb

Ruby
7
star
15

to_source

Generator for equivalent source from rubinius AST
Ruby
7
star
16

aql

The ArangoDB AQL AST and to_source implementation
Ruby
7
star
17

ruby-cdb

Ruby cdb reader and writer
C
6
star
18

guard-mutant

Mutant integration for guard
Ruby
6
star
19

mapper

A simple mapper without a latin name. (abandoned)
Ruby
6
star
20

axiom-fuzzer

A fuzzer for axiom relations
Ruby
6
star
21

assets

Playground for a nicer asset system
Ruby
6
star
22

response

Build HTTP responses
Ruby
5
star
23

request

Abstract not only the rack env in something more nice
Ruby
5
star
24

pgt

SQL Golden Testing Tool for postgresql
Haskell
5
star
25

ffprobe

Ruby wrapper around ffprobe
Ruby
4
star
26

eventstorm

unfinished zmq based event aggregation framework
Ruby
4
star
27

tasty-mgolden

A different golden testing provider for tasty.
Haskell
4
star
28

morpher

Transformation of ruby data-structures with optionally traced evaluation
Ruby
4
star
29

rz

Ruby ZeroMQ based jobserver with truly pulling workers
Ruby
3
star
30

openapi

OpenAPI datatypes
Haskell
3
star
31

axiom-sexp

Generate and load veritas relations from / to s-expressions
Ruby
3
star
32

lht

Lambda haskell tool / builds static binaries inside alpine containers
Haskell
3
star
33

db-migrations

Haskell Database Migrations for Postgresql
Haskell
3
star
34

ducktrap

The old soon to be unmaintained ducktrap. Successor is mbj/morpher
Ruby
3
star
35

source-constraints

GHC plugins to constrain the haskell source
Haskell
3
star
36

stack-deploy

Tooling around cloudformation templates
Haskell
3
star
37

mutant-rails-example

Mutant with rails example
Ruby
2
star
38

variable

Ruby concurrency variables MVar and IVar
Ruby
2
star
39

conversions

Haskell type conversions, another one.
Haskell
2
star
40

cbt

Container backend tool
2
star
41

devtools-hs

Haskell development tooling
Haskell
2
star
42

navigation

A web navigation dry up package
Ruby
1
star
43

sitemap_xml

Incomplete sitemap xml generator
Ruby
1
star
44

sunits

Depreciated sunits repo. Only used since some of my older projects will install from here!
Ruby
1
star
45

dump-parser

Simple and dump string 2 value DSL
Ruby
1
star
46

custom-resource

Custom CloudFormation Resources
Haskell
1
star
47

tinymagick

Simple ruby wrapper around imagemagick tools "identify" and "mogrify"
Ruby
1
star
48

html

Because XSS-free HTML generation is not about String#html_safe?
Ruby
1
star
49

mprelude

Very minimal prelude
Haskell
1
star
50

dm-annoing-modificators

Modification methods that raise on failure for datamapper.
Ruby
1
star
51

apk-build

My APK overlay and builder
Shell
1
star