Skip to content
This repository has been archived by the owner on Sep 18, 2019. It is now read-only.

Commit

Permalink
Updated documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
igor-alexandrov committed Jun 5, 2013
1 parent d6a81db commit 5af5886
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
11 changes: 10 additions & 1 deletion README.md
Expand Up @@ -37,7 +37,7 @@ class User
end
end
```

### Accessing attributes
By default Attrio defines `#attributes` accessor which contains `Hash` with attributes names as keys and instances of `Attrio::Attribute` as values. Each instance of `Attrio::Attribute` contains following information:
* type
* writer method name
Expand All @@ -55,6 +55,15 @@ user.attributes
# :age => #<Attrio::Attribute:0x007fc44e8d4c98 @object=#<User:0x007fc44e8b2b48>, @name="age", @type=Attrio::Types::Integer, @options={}, @writer_method_name="age=", @writer_visibility=:public, @instance_variable_name="@age", @reader_method_name="age", @reader_visibility=:public>,
# :birthday = >#<Attrio::Attribute:0x007fc44e8e2e38 @object=#<User:0x007fc44e8b2b48>, @name="birthday", @type=Attrio::Types::DateTime, @options={}, @writer_method_name="birthday=", @writer_visibility=:public, @instance_variable_name="@birthday", @reader_method_name="birthday", @reader_visibility=:public>
# }
user.attributes.keys
# => [:name, :age, :birthday]
```

Attributes can be filtered.

```ruby
user.attributes([:name, :age, :not_existing_attribute]).keys
# => [:name, :age]
```

Accessor name can be easily overridden by passing `:as` option to `define_attributes` block.
Expand Down
4 changes: 4 additions & 0 deletions spec/attrio/attrio_spec.rb
Expand Up @@ -44,6 +44,10 @@
subject.attributes(:name).keys.should match_array([:name])
subject.attributes([:name]).keys.should match_array([:name])
end

it 'should return a blank set of attributes for not existing filter' do
subject.attributes([:not_existing_attribute]).keys.should match_array([])
end
end
end
end
Expand Down

0 comments on commit 5af5886

Please sign in to comment.