https://github.com/bagilevi/elastic_attributes
Flexible attribute mapping
https://github.com/bagilevi/elastic_attributes
Last synced: 3 months ago
JSON representation
Flexible attribute mapping
- Host: GitHub
- URL: https://github.com/bagilevi/elastic_attributes
- Owner: bagilevi
- Created: 2010-09-25T22:07:35.000Z (over 14 years ago)
- Default Branch: master
- Last Pushed: 2010-09-25T22:10:47.000Z (over 14 years ago)
- Last Synced: 2025-02-15T02:05:54.479Z (3 months ago)
- Language: Ruby
- Homepage:
- Size: 89.8 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.rdoc
Awesome Lists containing this project
README
= Elastic attributes
Flexible attribute mapper. Input any ruby structure, map sub-structures to specified classes.
Can be used to map decoded JSON structures to objects, e.g. with document-oriented databases or JSON APIs.
== Examples
class Person
include ElasticAttributes
attribute :name, :is_default => true
endclass City
include ElasticAttributes
attribute :name, :is_default => true
attribute :mayor, Person
end
class Country
include ElasticAttributes
attribute :name, :is_default => true
attribute :cities, [Array, City] # Array of Cities
end
Country.from( 'Hungary' )
Country.from( {'name' => 'Hungary'} )
Country.from( {'name' => 'Hungary', 'cities' => ['Budapest', 'Miskolc', 'Debrecen']} )
Country.from( {'name' => 'Hungary', 'cities' => [{'name' => 'Budapest', 'mayor' => 'Demszky Gabor'},
'Miskolc',
'Debrecen']} )
City.from( {'name' => 'Budapest', 'mayor' => 'Demszky Gabor'} )
city = City.from( {'name' => 'Budapest', 'mayor' => {'name' => 'Demszky Gabor'}} )
city.encode # => {"name"=>"Budapest", "mayor"=>"Demszky Gabor"}== Installation
gem install elastic_attributes
== Licensehttp://sam.zoy.org/wtfpl/